@@ -253,13 +253,41 @@ function getJSONSchemaFromGraphQLType(
253
253
return { required, definition, definitions } ;
254
254
}
255
255
/**
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>.
257
257
*
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
260
261
*
261
262
* @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
+ * ```
263
291
*/
264
292
export function getVariablesJSONSchema (
265
293
variableToType : VariableToType ,
0 commit comments