graphql-config-parser
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "graphql-config-parser", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -38,3 +38,3 @@ # graphql-config | ||
You can either use your actual GraphQL endpoint or if preferred a local JSON schema file. | ||
You can either use your actual GraphQL endpoint or if preferred a local schema.json or schema.js file. | ||
@@ -64,3 +64,11 @@ #### Use GraphQL endpoint | ||
#### Use local schema file (GraphQL.js) | ||
```json | ||
{ | ||
"graphql-js": "./schema.js" | ||
} | ||
``` | ||
### Method 3: Configuration via `package.json` file | ||
@@ -67,0 +75,0 @@ |
@@ -13,2 +13,3 @@ "use strict"; | ||
const path_1 = require('path'); | ||
const graphql_1 = require('graphql/graphql'); | ||
const introspectionQuery_1 = require('graphql/utilities/introspectionQuery'); | ||
@@ -77,2 +78,5 @@ const fetch = require('node-fetch'); | ||
}); | ||
case 'graphql-js': | ||
const schemaSource = require(path_1.resolve(config.file)); | ||
return graphql_1.graphql(schemaSource, introspectionQuery_1.introspectionQuery); | ||
default: throw new Error(`Invalid config: ${JSON.stringify(config)}`); | ||
@@ -95,3 +99,9 @@ } | ||
} | ||
if (json['graphql-js']) { | ||
return { | ||
type: 'graphql-js', | ||
file: json['graphql-js'], | ||
}; | ||
} | ||
throw new Error(`Invalid configuration file: ${JSON.stringify(json)}`); | ||
} |
import { isWebUri } from 'valid-url' | ||
import { readFileSync } from 'fs' | ||
import { join } from 'path' | ||
import { join, resolve } from 'path' | ||
import { graphql } from 'graphql/graphql' | ||
import { introspectionQuery } from 'graphql/utilities/introspectionQuery' | ||
import * as fetch from 'node-fetch' | ||
type Config = ConfigFile | ConfigRequest | ||
type Config = ConfigFile | ConfigRequest | ConfigGraphQLJS | ||
@@ -20,2 +21,7 @@ interface ConfigFile { | ||
interface ConfigGraphQLJS { | ||
type: 'graphql-js', | ||
file: string | ||
} | ||
interface Schema { | ||
@@ -92,2 +98,6 @@ data: any | ||
}) | ||
case 'graphql-js': | ||
const schemaSource = require(resolve(config.file)) | ||
return graphql(schemaSource, introspectionQuery) | ||
default: throw new Error(`Invalid config: ${JSON.stringify(config)}`) | ||
@@ -114,3 +124,10 @@ } | ||
if (json['graphql-js']) { | ||
return { | ||
type: 'graphql-js', | ||
file: json['graphql-js'], | ||
} as ConfigGraphQLJS | ||
} | ||
throw new Error(`Invalid configuration file: ${JSON.stringify(json)}`) | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
16288
217
118
6