Skip to content

Commit 313d930

Browse files
committed
remove json-schema type from dependencies
1 parent 5eff191 commit 313d930

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

packages/graphql-language-service/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
"dependencies": {
3434
"graphql-config": "^4.1.0",
3535
"vscode-languageserver-types": "^3.15.1",
36-
"nullthrows": "^1.0.0",
37-
"@types/json-schema": "7.0.9"
36+
"nullthrows": "^1.0.0"
3837
},
3938
"devDependencies": {
4039
"@types/picomatch": "^2.3.0",
4140
"@types/benchmark": "^1.0.33",
41+
"@types/json-schema": "7.0.9",
4242
"benchmark": "^2.1.4",
4343
"graphql": "16.0.0-experimental-stream-defer.5",
4444
"lodash": "^4.17.15",

packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts

+32-4
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,41 @@ function getJSONSchemaFromGraphQLType(
253253
return { required, definition, definitions };
254254
}
255255
/**
256-
* Generate a JSONSchema6 valid document from a map of Map<string, GraphQLInputDefinition>
256+
* Generates a JSONSchema6 valid document for operation(s) from a map of Map<string, GraphQLInputType>.
257257
*
258-
* TODO: optimize with shared definitions.
259-
* Otherwise, if you have multiple variables in your operations with the same input type, they are repeated.
258+
* It generates referenced Definitions for each type, so that no graphql types are repeated.
259+
*
260+
* Note: you must install `@types/json-schema` if you want a valid result type
260261
*
261262
* @param facts {OperationFacts} the result of getOperationFacts, or getOperationASTFacts
262-
* @returns {JSONSchema6}
263+
* @returns {JSONSchema6}'
264+
*
265+
* @example
266+
* simple usage:
267+
*
268+
* ```ts
269+
* import { parse } from 'graphql'
270+
* import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
271+
* const variablesToType = collectVariables(parse(query), schema)
272+
* const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema)
273+
* ```
274+
*
275+
* @example
276+
* advanced usage:
277+
* ```ts
278+
*
279+
* import { parse } from 'graphql'
280+
* import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
281+
* const variablesToType = collectVariables(parse(query), schema)
282+
*
283+
* // you can append `markdownDescription` to JSON schema, which monaco-json uses.
284+
* const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema, { useMarkdownDescription: true })
285+
*
286+
* // let's say we want to use it with an IDE extension that expects a JSON file
287+
* // the resultant object literal can be written to string
288+
* import fs from 'fs/promises'
289+
* await fs.writeFile('operation-schema.json', JSON.stringify(JSONSchema6Result, null, 2))
290+
* ```
263291
*/
264292
export function getVariablesJSONSchema(
265293
variableToType: VariableToType,

0 commit comments

Comments
 (0)