Skip to content

Commit

Permalink
remove json-schema type from dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Mar 11, 2022
1 parent 5eff191 commit 313d930
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/graphql-language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"dependencies": {
"graphql-config": "^4.1.0",
"vscode-languageserver-types": "^3.15.1",
"nullthrows": "^1.0.0",
"@types/json-schema": "7.0.9"
"nullthrows": "^1.0.0"
},
"devDependencies": {
"@types/picomatch": "^2.3.0",
"@types/benchmark": "^1.0.33",
"@types/json-schema": "7.0.9",
"benchmark": "^2.1.4",
"graphql": "16.0.0-experimental-stream-defer.5",
"lodash": "^4.17.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,41 @@ function getJSONSchemaFromGraphQLType(
return { required, definition, definitions };
}
/**
* Generate a JSONSchema6 valid document from a map of Map<string, GraphQLInputDefinition>
* Generates a JSONSchema6 valid document for operation(s) from a map of Map<string, GraphQLInputType>.
*
* TODO: optimize with shared definitions.
* Otherwise, if you have multiple variables in your operations with the same input type, they are repeated.
* It generates referenced Definitions for each type, so that no graphql types are repeated.
*
* Note: you must install `@types/json-schema` if you want a valid result type
*
* @param facts {OperationFacts} the result of getOperationFacts, or getOperationASTFacts
* @returns {JSONSchema6}
* @returns {JSONSchema6}'
*
* @example
* simple usage:
*
* ```ts
* import { parse } from 'graphql'
* import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
* const variablesToType = collectVariables(parse(query), schema)
* const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema)
* ```
*
* @example
* advanced usage:
* ```ts
*
* import { parse } from 'graphql'
* import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
* const variablesToType = collectVariables(parse(query), schema)
*
* // you can append `markdownDescription` to JSON schema, which monaco-json uses.
* const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema, { useMarkdownDescription: true })
*
* // let's say we want to use it with an IDE extension that expects a JSON file
* // the resultant object literal can be written to string
* import fs from 'fs/promises'
* await fs.writeFile('operation-schema.json', JSON.stringify(JSONSchema6Result, null, 2))
* ```
*/
export function getVariablesJSONSchema(
variableToType: VariableToType,
Expand Down

0 comments on commit 313d930

Please sign in to comment.