diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 4d364d8382..fcbd4703df 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -91,24 +91,24 @@ cd website npm run generate:docs -- 16.x.x 17.x.x ``` -The generator creates detached temporary git worktrees for the refs passed on -the command line, infers the major version from each ref's `package.json`, and -writes the corresponding `api-v*` output directory. Generated API docs are not -published automatically at this time; PRs that change website API output must -include the generated files. - -Because the generator reads refs through temporary worktrees, it does not read -uncommitted changes from your current checkout. Passing `17.x.x` reads the -committed tip of the `17.x.x` branch, not local changes in a checked-out -worktree. If a PR changes v17 API source comments or exported TypeScript -surfaces, commit those source changes first and generate v17 docs from a ref -that includes them, for example: +Each argument is either `local` or a local git ref such as a branch, tag, SHA, +or `HEAD`. For git refs, the generator creates detached temporary worktrees. For +`local`, it snapshots the current working tree, including uncommitted changes. +The generator infers the major version from each source's `package.json`, writes +the corresponding `api-v*` output directory, and fails if more than one input +resolves to the same major version. + +Use `local` when a PR changes API source comments or exported TypeScript +surfaces and you want to regenerate docs before committing those source changes: ```bash cd website -npm run generate:docs -- 16.x.x HEAD +npm run generate:docs -- 16.x.x local ``` +Generated API docs are not published automatically at this time; PRs that +change website API output must include the generated files. + ## Review and Merge Process - Pull requests are required to pass all tests and checks before they can be merged. diff --git a/website/generate-api.js b/website/generate-api.js index dfca9017b9..30b2e3c344 100644 --- a/website/generate-api.js +++ b/website/generate-api.js @@ -11,25 +11,25 @@ import { rmSync, writeFileSync, } from 'node:fs'; -import { createRequire } from 'node:module'; import { tmpdir } from 'node:os'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; +import prettier from 'prettier'; +import ts from 'typescript'; + const __dirname = dirname(fileURLToPath(import.meta.url)); const repoRoot = resolve(__dirname, '..'); const websiteDir = __dirname; -const repoRequire = createRequire(join(repoRoot, 'package.json')); -const websiteRequire = createRequire(join(websiteDir, 'package.json')); const typedocTemplatePath = join(__dirname, 'typedoc-api.json'); const tmpDir = mkdtempSync(join(tmpdir(), 'graphql-js-api-')); -const prettier = repoRequire('prettier'); -const ts = websiteRequire('typescript'); -const prettierConfig = prettier.resolveConfig.sync(repoRoot) ?? {}; -const signaturePrettierOptions = { - ...prettierConfig, - parser: 'typescript', -}; +const signaturePrettierOptionsPromise = prettier + .resolveConfig(join(repoRoot, 'package.json')) + .then((prettierConfig) => ({ + ...(prettierConfig ?? {}), + parser: 'typescript', + })); +const LOCAL = 'local'; let generation = { docsVersionLabel: 'api-docs', @@ -125,6 +125,10 @@ function checkoutSourceRef(ref, index) { return dir; } +function sourceDirForRef(ref, index) { + return ref === LOCAL ? repoRoot : checkoutSourceRef(ref, index); +} + function removeSourceWorktrees() { for (let i = worktreeDirs.length - 1; i >= 0; i--) { const dir = worktreeDirs[i]; @@ -1563,9 +1567,11 @@ function signatureSourceTypeLink(ctx, name) { ); } -function formatSignatureSource(source) { +async function formatSignatureSource(source) { try { - return prettier.format(source, signaturePrettierOptions).trimEnd(); + return ( + await prettier.format(source, await signaturePrettierOptionsPromise) + ).trimEnd(); } catch (error) { fail(`Cannot format API signature source:\n${source}\n\n${error.message}`); } @@ -1592,15 +1598,19 @@ function signatureSourceText(value) { ); } -function formatInterfaceMemberSource(memberSource) { +async function formatInterfaceMemberSource(memberSource) { return formatDeclarationBody( - formatSignatureSource(`interface __ApiSignature {\n${memberSource}\n}`), + await formatSignatureSource( + `interface __ApiSignature {\n${memberSource}\n}`, + ), ); } -function formatClassMemberSource(memberSource) { +async function formatClassMemberSource(memberSource) { return formatDeclarationBody( - formatSignatureSource(`declare class __ApiSignature {\n${memberSource}\n}`), + await formatSignatureSource( + `declare class __ApiSignature {\n${memberSource}\n}`, + ), ); } @@ -1609,10 +1619,10 @@ function formatDeclarationBody(source) { return lines.slice(1, -1).join('\n').replace(/^ {2}/gm, '').trim(); } -function formatTypeSource(type, options = {}) { +async function formatTypeSource(type, options = {}) { const ctx = createSignatureSourceContext(options); const source = signatureTypeSource(type, ctx); - const formatted = formatInterfaceMemberSource(`__api(): ${source};`); + const formatted = await formatInterfaceMemberSource(`__api(): ${source};`); const body = extractReturnTypeBody(formatted); return renderFormattedSignatureSource(body, ctx); } @@ -2124,13 +2134,13 @@ function typeLiteralMembers(node, options, renderIndexSignature, renderChild) { ]; } -function renderApiType(type, options = {}) { +async function renderApiType(type, options = {}) { return ``; } -function renderSignatureDeclaration( +async function renderSignatureDeclaration( signature, options = {}, name = signature.name, @@ -2146,11 +2156,14 @@ function renderSignatureDeclaration( includeDefault: true, })}): ${signatureTypeSource(signature.type, ctx)};`; return apiSignature( - renderFormattedSignatureSource(formatInterfaceMemberSource(source), ctx), + renderFormattedSignatureSource( + await formatInterfaceMemberSource(source), + ctx, + ), ); } -function renderConstructorDeclaration(signature, options = {}) { +async function renderConstructorDeclaration(signature, options = {}) { const ctx = createSignatureSourceContext(options); const source = `constructor(${signatureParametersSource(signature, ctx, { includeDefault: true, @@ -2161,7 +2174,7 @@ function renderConstructorDeclaration(signature, options = {}) { ); return apiSignature( renderFormattedSignatureSource( - formatClassMemberSource(source).replace( + (await formatClassMemberSource(source)).replace( /^constructor/, constructorSource, ), @@ -2170,7 +2183,7 @@ function renderConstructorDeclaration(signature, options = {}) { ); } -function renderTypeAliasDeclaration(node, options = {}) { +async function renderTypeAliasDeclaration(node, options = {}) { const ctx = createSignatureSourceContext(options); const source = `type ${signatureNameSource( ctx, @@ -2180,7 +2193,7 @@ function renderTypeAliasDeclaration(node, options = {}) { ctx, )};`; return apiSignature( - renderFormattedSignatureSource(formatSignatureSource(source), ctx), + renderFormattedSignatureSource(await formatSignatureSource(source), ctx), ); } @@ -2330,7 +2343,7 @@ function renderComment(node) { return parts.join('\n\n'); } -function renderFields(parent, level, options = {}) { +async function renderFields(parent, level, options = {}) { const children = visibleChildren(parent).filter( (child) => child.kind === ReflectionKind.Property || @@ -2347,7 +2360,8 @@ function renderFields(parent, level, options = {}) { if (rows.length > 0 || lines.length > 0) { lines.push('
'); } - lines.push(...renderCallable(child, level, child.name)); + // eslint-disable-next-line no-await-in-loop + lines.push(...(await renderCallable(child, level, child.name))); continue; } const defaultValue = defaultText(child, parent, options); @@ -2355,7 +2369,8 @@ function renderFields(parent, level, options = {}) { `${htmlText(child.name)}${ child.flags?.isOptional ? '?' : '' }${deprecatedTag(child)}`, - renderApiType(child.type, options), + // eslint-disable-next-line no-await-in-loop + await renderApiType(child.type, options), defaultValue, summary(child), ]); @@ -2370,7 +2385,7 @@ function renderFields(parent, level, options = {}) { : [...subsection('Members', members), ...lines]; } -function renderParams(signature, options = {}) { +async function renderParams(signature, options = {}) { const params = signature.parameters ?? []; if (params.length === 0) { return []; @@ -2383,7 +2398,8 @@ function renderParams(signature, options = {}) { `${htmlText(param.name)}${ param.flags?.isOptional ? '?' : '' }${deprecatedTag(param)}`, - renderApiType(param.type, options), + // eslint-disable-next-line no-await-in-loop + await renderApiType(param.type, options), defaultValue, summary(param), ]); @@ -2432,7 +2448,7 @@ function renderExamples(comment, title = 'Example') { ); } -function renderReturns(signature, options = {}) { +async function renderReturns(signature, options = {}) { if (signature.type == null || typeName(signature.type, options) === 'void') { return []; } @@ -2445,23 +2461,36 @@ function renderReturns(signature, options = {}) { return subsection('Returns', [ ...table([ ['Type', 'Description'], - [renderApiType(signature.type, options), returns], + [await renderApiType(signature.type, options), returns], ]), ]); } -function renderTypeParameters(node, options = {}) { +async function renderTypeParameters(node, options = {}) { const typeParameters = node.typeParameters ?? []; if (typeParameters.length === 0) { return []; } - const rows = typeParameters.map((param) => [ - `${param.name}${deprecatedTag(param)}`, - param.type == null ? '' : renderApiType(param.type, options), - param.default == null ? '' : renderApiType(param.default, options), - summary(param), - ]); + const rows = []; + for (const param of typeParameters) { + let constraint = ''; + if (param.type != null) { + // eslint-disable-next-line no-await-in-loop + constraint = await renderApiType(param.type, options); + } + let defaultType = ''; + if (param.default != null) { + // eslint-disable-next-line no-await-in-loop + defaultType = await renderApiType(param.default, options); + } + rows.push([ + `${param.name}${deprecatedTag(param)}`, + constraint, + defaultType, + summary(param), + ]); + } return subsection('Type Parameters', [ ...table([['Name', 'Constraint', 'Default', 'Description'], ...rows]), ]); @@ -2478,7 +2507,7 @@ function publishedExtendedTypes(node) { }); } -function renderInterfaceDeclaration(node, options = {}) { +async function renderInterfaceDeclaration(node, options = {}) { const extendedTypes = publishedExtendedTypes(node); if (extendedTypes.length === 0) { return ''; @@ -2493,13 +2522,13 @@ function renderInterfaceDeclaration(node, options = {}) { .join(', ')} {}`; return apiSignature( renderFormattedSignatureSource( - formatSignatureSource(source).replace(/\s*\{\}$/, ''), + (await formatSignatureSource(source)).replace(/\s*\{\}$/, ''), ctx, ), ); } -function renderCallable( +async function renderCallable( node, level, label = `${node.name}()`, @@ -2530,19 +2559,24 @@ function renderCallable( if (comment) { lines.push(comment); } - lines.push(...renderTypeParameters(signature, options)); - lines.push( - '**Signature:**', - renderSignatureDeclaration(signature, options), + // eslint-disable-next-line no-await-in-loop + lines.push(...(await renderTypeParameters(signature, options))); + // eslint-disable-next-line no-await-in-loop + const signatureDeclaration = await renderSignatureDeclaration( + signature, + options, ); - lines.push(...renderParams(signature, options)); - lines.push(...renderReturns(signature, options)); + lines.push('**Signature:**', signatureDeclaration); + // eslint-disable-next-line no-await-in-loop + lines.push(...(await renderParams(signature, options))); + // eslint-disable-next-line no-await-in-loop + lines.push(...(await renderReturns(signature, options))); lines.push(...renderExamples(signature.comment)); } return lines; } -function renderDeclaration(node, level = 3, siblings = []) { +async function renderDeclaration(node, level = 3, siblings = []) { const declaration = documentationNode(node); if (declaration !== node) { return renderDeclaration( @@ -2571,7 +2605,7 @@ function renderDeclaration(node, level = 3, siblings = []) { lines.push(comment); } - lines.push(...renderTypeParameters(node, options)); + lines.push(...(await renderTypeParameters(node, options))); const examples = renderExamples(node.comment); if (isEnumLikeDeclaration(node, siblings)) { @@ -2581,13 +2615,15 @@ function renderDeclaration(node, level = 3, siblings = []) { return lines; } - const interfaceDeclaration = renderInterfaceDeclaration(node, options); + const interfaceDeclaration = await renderInterfaceDeclaration(node, options); if (interfaceDeclaration) { lines.push(interfaceDeclaration); } if (node.kind === ReflectionKind.Variable) { - lines.push(...subsection('Type', [renderApiType(node.type, options)])); + lines.push( + ...subsection('Type', [await renderApiType(node.type, options)]), + ); lines.push(...examples); return lines; } @@ -2597,7 +2633,7 @@ function renderDeclaration(node, level = 3, siblings = []) { node.kind === ReflectionKind.Reference) && node.type != null ) { - lines.push(renderTypeAliasDeclaration(node, options)); + lines.push(await renderTypeAliasDeclaration(node, options)); } if (node.kind === ReflectionKind.Enum) { @@ -2632,11 +2668,14 @@ function renderDeclaration(node, level = 3, siblings = []) { if (signatureComment) { lines.push(signatureComment); } - lines.push( - '**Signature:**', - renderConstructorDeclaration(signature, options), + // eslint-disable-next-line no-await-in-loop + const constructorDeclaration = await renderConstructorDeclaration( + signature, + options, ); - lines.push(...renderParams(signature, options)); + lines.push('**Signature:**', constructorDeclaration); + // eslint-disable-next-line no-await-in-loop + lines.push(...(await renderParams(signature, options))); } } } else { @@ -2644,10 +2683,10 @@ function renderDeclaration(node, level = 3, siblings = []) { } lines.push( - ...renderFields(node, level + 1, { + ...(await renderFields(node, level + 1, { ...options, heading: node.kind === ReflectionKind.Class, - }), + })), ); return lines; } @@ -2852,7 +2891,7 @@ function sameDoc(left, right) { return left.page === right.page && left.anchor === right.anchor; } -function renderGroup(title, items, level, allItems) { +async function renderGroup(title, items, level, allItems) { if (items.length === 0) { return []; } @@ -2861,7 +2900,8 @@ function renderGroup(title, items, level, allItems) { if (index > 0) { lines.push('
'); } - lines.push(...renderDeclaration(item, level + 1, allItems)); + // eslint-disable-next-line no-await-in-loop + lines.push(...(await renderDeclaration(item, level + 1, allItems))); } return lines; } @@ -2880,11 +2920,12 @@ function grouped(items) { return map; } -function renderItems(items, page, level = 2) { +async function renderItems(items, page, level = 2) { const groups = grouped(items); const lines = [renderItemToc(groups, page)]; for (const group of groupOrder) { - lines.push(...renderGroup(group, groups.get(group), level, items)); + // eslint-disable-next-line no-await-in-loop + lines.push(...(await renderGroup(group, groups.get(group), level, items))); } return lines.filter(Boolean).join('\n\n').trimEnd() + '\n'; } @@ -2983,14 +3024,14 @@ function categoryHeading(categoryName) { return `Category: ${categoryName}`; } -function categorySection(name, items, moduleName) { +async function categorySection(name, items, moduleName) { return [ heading(2, categoryHeading(name)), - renderItems(items, moduleName, 3).trimEnd(), + (await renderItems(items, moduleName, 3)).trimEnd(), ].join('\n\n'); } -function renderModulePage(docs) { +async function renderModulePage(docs) { const content = []; if (isDeprecatedModule(docs)) { content.push(heading(1, deprecatedHeadingLabel(docs.title, true))); @@ -2998,14 +3039,18 @@ function renderModulePage(docs) { content.push(summary(docs.module)); if (docs.categories.length === 1) { content.push( - renderItems(docs.byCategory.get(docs.categories[0]), docs.name).trimEnd(), + ( + await renderItems(docs.byCategory.get(docs.categories[0]), docs.name) + ).trimEnd(), ); } else { content.push(categoryLinks(docs.categories, docs.name)); content.push( - ...docs.categories.map((name) => - categorySection(name, docs.byCategory.get(name), docs.name), - ), + ...(await Promise.all( + docs.categories.map((name) => + categorySection(name, docs.byCategory.get(name), docs.name), + ), + )), ); } return content.filter(Boolean).join('\n\n') + '\n'; @@ -3066,7 +3111,7 @@ function buildApiReference(doc) { }; } -function writeApiReference(reference) { +async function writeApiReference(reference) { renderContext.docsBasePath = generation.docsBasePath; renderContext.docsIndex = reference.index; renderContext.reflectionsById = reference.reflectionsById; @@ -3078,15 +3123,16 @@ function writeApiReference(reference) { for (const docs of reference.modules) { addModuleMeta(meta, docs); assertAllItemsCategorized(docs); - writePage(docs.name, renderModulePage(docs)); + // eslint-disable-next-line no-await-in-loop + writePage(docs.name, await renderModulePage(docs)); writeCategoryMeta(docs); } writeMeta(generation.outputDir, meta); } -function renderDocs(doc) { - writeApiReference(buildApiReference(doc)); +async function renderDocs(doc) { + await writeApiReference(buildApiReference(doc)); } function addCategory(comment, category) { @@ -3376,13 +3422,32 @@ function typedocEntryPoints(sourceRootDir) { .filter((path) => existsSync(path)); } -function rememberGeneratedMajor(generatedMajors, majorVersion) { - if (generatedMajors.has(majorVersion)) { - fail( - `Multiple refs resolve to v${majorVersion}; refusing to overwrite docs.`, - ); +function assertUniqueMajorVersions(sources) { + const sourceByMajor = new Map(); + for (const source of sources) { + const previousRef = sourceByMajor.get(source.majorVersion); + if (previousRef != null) { + fail( + `Multiple refs resolve to v${source.majorVersion}: ${previousRef} and ${source.ref}. Refusing to overwrite docs.`, + ); + } + sourceByMajor.set(source.majorVersion, source.ref); } - generatedMajors.add(majorVersion); +} + +function generationSources(refs) { + const sources = refs.map((ref, index) => { + const sourceDir = sourceDirForRef(ref, index); + assertSourceRoot(sourceDir); + return { + majorVersion: sourceMajorVersion(sourceDir), + ref, + sourceDir, + }; + }); + + assertUniqueMajorVersions(sources); + return sources; } function runTypedoc(ref) { @@ -3405,37 +3470,50 @@ function readTypedocOutput() { return readJson(generation.jsonPath); } -function generateForRef(ref, index, generatedMajors) { - const sourceCheckoutDir = checkoutSourceRef(ref, index); - const majorVersion = configureGeneration(ref, sourceCheckoutDir); - rememberGeneratedMajor(generatedMajors, majorVersion); +async function generateForSource(source) { + configureGeneration(source.ref, source.sourceDir); prepareSourceSnapshot(); sourceContext = analyzeSourceSnapshot(generation.tmpSourceDir); - runTypedoc(ref); - renderDocs(readTypedocOutput()); + runTypedoc(source.ref); + await renderDocs(readTypedocOutput()); } -function generateRefs(refs) { +async function generateRefs(refs) { if (refs.length === 0) { - fail('Usage: npm run generate:docs [...branch-or-ref]'); + fail('Usage: npm run generate:docs [...local-or-ref]'); } - const generatedMajors = new Set(); - for (const [index, ref] of refs.entries()) { - generateForRef(ref, index, generatedMajors); + const sources = generationSources(refs); + for (const source of sources) { + // eslint-disable-next-line no-await-in-loop + await generateForSource(source); } } -try { - generateRefs(process.argv.slice(2)); -} catch (error) { - console.error(error.message); - process.exitCode = 1; -} finally { - removeSourceWorktrees(); - if (process.env.GRAPHQL_JS_API_KEEP_TMP === '1') { - console.error('[api-docs] Kept temporary directory:', tmpDir); - } else { - rmSync(tmpDir, { recursive: true, force: true }); +async function main() { + let exitCode = 0; + try { + await generateRefs(process.argv.slice(2)); + } catch (error) { + console.error(error.message); + exitCode = 1; + } finally { + removeSourceWorktrees(); + if (process.env.GRAPHQL_JS_API_KEEP_TMP === '1') { + console.error('[api-docs] Kept temporary directory:', tmpDir); + } else { + rmSync(tmpDir, { recursive: true, force: true }); + } } + return exitCode; } + +main().then( + (exitCode) => { + process.exitCode = exitCode; + }, + (error) => { + console.error(error.message); + process.exitCode = 1; + }, +); diff --git a/website/package-lock.json b/website/package-lock.json index 553fa16fca..a35672158b 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -16,6 +16,7 @@ "nextra": "^3.0.13", "nextra-theme-docs": "^3.0.13", "postcss": "^8.4.47", + "prettier": "3.8.4", "react": "^18.3.1", "react-dom": "^18.3.1", "tailwindcss": "^3.4.14", @@ -7828,6 +7829,22 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", "dev": true }, + "node_modules/prettier": { + "version": "3.8.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.4.tgz", + "integrity": "sha512-N2MylSdi48+5N/6S5j+maeHbUSIzzZ5uOcX5Hm4QpV8Dkb1HFjfAKTKX6yNPJQD9AhcT3ifHNB66tWTTJDi11Q==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/property-information": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/property-information/-/property-information-6.5.0.tgz", diff --git a/website/package.json b/website/package.json index c83b15d59c..4e7c9a32d8 100644 --- a/website/package.json +++ b/website/package.json @@ -21,6 +21,7 @@ "nextra": "^3.0.13", "nextra-theme-docs": "^3.0.13", "postcss": "^8.4.47", + "prettier": "3.8.4", "react": "^18.3.1", "react-dom": "^18.3.1", "tailwindcss": "^3.4.14", diff --git a/website/pages/api-v17/error.mdx b/website/pages/api-v17/error.mdx index 84e57ffff8..180ec1a7b9 100644 --- a/website/pages/api-v17/error.mdx +++ b/website/pages/api-v17/error.mdx @@ -298,9 +298,7 @@ import { locatedError } from 'graphql/error'; const document = parse('{ viewer { name } }'); const fieldNode = document.definitions[0].selectionSet.selections[0]; -const error = locatedError(new Error('Resolver failed'), fieldNode, [ - 'viewer', -]); +const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']); error.message; // => 'Resolver failed' error.locations; // => [{ line: 1, column: 3 }] diff --git a/website/pages/api-v17/execution.mdx b/website/pages/api-v17/execution.mdx index 35ab089cd6..3355042eb8 100644 --- a/website/pages/api-v17/execution.mdx +++ b/website/pages/api-v17/execution.mdx @@ -317,7 +317,10 @@ this case is the entire response. import assert from 'node:assert'; import { parse } from 'graphql/language'; import { buildSchema } from 'graphql/utilities'; -import { executeRootSelectionSet, validateExecutionArgs } from 'graphql/execution'; +import { + executeRootSelectionSet, + validateExecutionArgs, +} from 'graphql/execution'; const schema = buildSchema('type Query { greeting: String }'); const validatedArgs = validateExecutionArgs({ @@ -465,7 +468,10 @@ or rejecting the returned promise. import assert from 'node:assert'; import { parse } from 'graphql/language'; import { buildSchema } from 'graphql/utilities'; -import { executeSubscriptionEvent, validateSubscriptionArgs } from 'graphql/execution'; +import { + executeSubscriptionEvent, + validateSubscriptionArgs, +} from 'graphql/execution'; const schema = buildSchema(` type Query { @@ -738,7 +744,10 @@ or otherwise separating these two steps. For more on this, see the import assert from 'node:assert'; import { parse } from 'graphql/language'; import { buildSchema } from 'graphql/utilities'; -import { createSourceEventStream, validateSubscriptionArgs } from 'graphql/execution'; +import { + createSourceEventStream, + validateSubscriptionArgs, +} from 'graphql/execution'; async function* greetings() { yield { greeting: 'Hello' }; @@ -1028,7 +1037,10 @@ stream to an ExecutionResult in the response stream. import assert from 'node:assert'; import { parse } from 'graphql/language'; import { buildSchema } from 'graphql/utilities'; -import { mapSourceToResponseEvent, validateSubscriptionArgs } from 'graphql/execution'; +import { + mapSourceToResponseEvent, + validateSubscriptionArgs, +} from 'graphql/execution'; async function* events() { yield { greeting: 'Hello' }; @@ -3770,11 +3782,9 @@ const document = parse(` `); const operation = document.definitions[0]; -const result = getVariableValues( - schema, - operation.variableDefinitions, - { stars: '5' }, -); +const result = getVariableValues(schema, operation.variableDefinitions, { + stars: '5', +}); assert('variableValues' in result); @@ -3938,11 +3948,9 @@ const fieldDef = schema.getQueryType().getFields().reviews; const document = parse('query ($stars: Int!) { reviews(stars: $stars) }'); const operation = document.definitions[0]; const fieldNode = document.definitions[0].selectionSet.selections[0]; -const variables = getVariableValues( - schema, - operation.variableDefinitions, - { stars: '5' }, -); +const variables = getVariableValues(schema, operation.variableDefinitions, { + stars: '5', +}); assert('variableValues' in variables); @@ -4056,18 +4064,22 @@ import { buildSchema } from 'graphql/utilities'; import { getDirectiveValues, getVariableValues } from 'graphql/execution'; const schema = buildSchema('type Query { name: String }'); -const document = parse('query ($includeName: Boolean!) { name @include(if: $includeName) }'); +const document = parse( + 'query ($includeName: Boolean!) { name @include(if: $includeName) }', +); const operation = document.definitions[0]; const fieldNode = document.definitions[0].selectionSet.selections[0]; -const variables = getVariableValues( - schema, - operation.variableDefinitions, - { includeName: false }, -); +const variables = getVariableValues(schema, operation.variableDefinitions, { + includeName: false, +}); assert('variableValues' in variables); -getDirectiveValues(GraphQLIncludeDirective, fieldNode, variables.variableValues); // => { if: false } +getDirectiveValues( + GraphQLIncludeDirective, + fieldNode, + variables.variableValues, +); // => { if: false } getDirectiveValues(GraphQLIncludeDirective, { directives: [] }); // => undefined ``` diff --git a/website/pages/api-v17/graphql.mdx b/website/pages/api-v17/graphql.mdx index f0fa336f4c..a338721cba 100644 --- a/website/pages/api-v17/graphql.mdx +++ b/website/pages/api-v17/graphql.mdx @@ -965,7 +965,7 @@ options, and an optional harness for replacing pipeline stages. `@stream`); use [`experimentalExecuteIncrementally`](/api-v17/execution#experimentalexecuteincrementally) after parsing and validating when incremental delivery is required. - +
diff --git a/website/pages/api-v17/language.mdx b/website/pages/api-v17/language.mdx index de353e40b3..3d17761dd9 100644 --- a/website/pages/api-v17/language.mdx +++ b/website/pages/api-v17/language.mdx @@ -4254,18 +4254,21 @@ document.kind; // => 'Document' // This variant enables parser options and provides an explicit lexer. import { Lexer, Source, parse } from 'graphql/language'; -const document = parse(` +const document = parse( + ` + { + t { ...A(var: true) } + } + fragment A($var: Boolean = false) on T { + name + } + `, { - t { ...A(var: true) } - } - fragment A($var: Boolean = false) on T { - name - } -`, { - experimentalFragmentArguments: true, - maxTokens: 80, - noLocation: true, -}); + experimentalFragmentArguments: true, + maxTokens: 80, + noLocation: true, + }, +); const directiveDocument = parse('directive @foo @bar on FIELD', { experimentalDirectivesOnDirectiveDefinitions: true, }); @@ -4622,7 +4625,7 @@ This syntax is not part of the GraphQL specification and may change.
experimentalFragmentArguments Example
-```graphql +```graphql prettier-ignore { t { ...A(var: true) } } @@ -4635,7 +4638,7 @@ fragment A($var: Boolean = false) on T {
experimentalDirectivesOnDirectiveDefinitions Example
-```graphql +```graphql prettier-ignore directive @foo @bar on FIELD ``` @@ -5047,7 +5050,11 @@ Returns true when the AST node is a constant value node.
Example
```ts -import { parseConstValue, parseValue, isConstValueNode } from 'graphql/language'; +import { + parseConstValue, + parseValue, + isConstValueNode, +} from 'graphql/language'; const value = parseConstValue('[42]'); const variable = parseValue('$id'); @@ -5936,8 +5943,16 @@ const events = []; visit( document, visitInParallel([ - { Field: (node) => { events.push(`field:${node.name.value}`); } }, - { Name: (node) => { events.push(`name:${node.value}`); } }, + { + Field: (node) => { + events.push(`field:${node.name.value}`); + }, + }, + { + Name: (node) => { + events.push(`name:${node.value}`); + }, + }, ]), ); diff --git a/website/pages/api-v17/type.mdx b/website/pages/api-v17/type.mdx index 0d305773b3..97c543fa3b 100644 --- a/website/pages/api-v17/type.mdx +++ b/website/pages/api-v17/type.mdx @@ -474,8 +474,8 @@ const PersonType = new GraphQLObjectType({ fields: () => ({ parents: { type: new GraphQLList(PersonType) }, children: { type: new GraphQLList(PersonType) }, - }) -}) + }), +}); ```
@@ -659,8 +659,8 @@ const RowType = new GraphQLObjectType({ name: 'Row', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString) }, - }) -}) + }), +}); ``` Note: the enforcement of non-nullability occurs within the executor. @@ -754,9 +754,7 @@ Returns this wrapping type as a GraphQL type-reference string. import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type'; const requiredString = new GraphQLNonNull(GraphQLString); -const requiredStringList = new GraphQLNonNull( - new GraphQLList(GraphQLString), -); +const requiredStringList = new GraphQLNonNull(new GraphQLList(GraphQLString)); requiredString.toString(); // => 'String!' requiredStringList.toString(); // => '[String]!' @@ -897,7 +895,9 @@ const ensureOdd = (value) => { } if (value % 2 === 0) { - throw new Error(`Scalar "Odd" cannot represent "${value}" since it is even.`); + throw new Error( + `Scalar "Odd" cannot represent "${value}" since it is even.`, + ); } return value; @@ -913,7 +913,7 @@ const OddType = new GraphQLScalarType({ }, valueToLiteral: (value) => { return { kind: Kind.INT, value: String(ensureOdd(value)) }; - } + }, }); ``` @@ -1223,10 +1223,10 @@ const AddressType = new GraphQLObjectType({ formatted: { type: GraphQLString, resolve: (obj) => { - return obj.number + ' ' + obj.street - } - } - } + return obj.number + ' ' + obj.street; + }, + }, + }, }); ``` @@ -1244,7 +1244,7 @@ const PersonType = new GraphQLObjectType({ fields: () => ({ name: { type: GraphQLString }, bestFriend: { type: PersonType }, - }) + }), }); ``` @@ -1631,8 +1631,8 @@ when the field is resolved. const EntityType = new GraphQLInterfaceType({ name: 'Entity', fields: { - name: { type: GraphQLString } - } + name: { type: GraphQLString }, + }, }); ``` @@ -2038,7 +2038,7 @@ const PetType = new GraphQLUnionType({ if (value instanceof Cat) { return CatType; } - } + }, }); ``` @@ -2211,7 +2211,11 @@ Returns a normalized configuration object for this object.
Example
```ts -import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type'; +import { + GraphQLObjectType, + GraphQLString, + GraphQLUnionType, +} from 'graphql/type'; const Photo = new GraphQLObjectType({ name: 'Photo', @@ -2320,7 +2324,11 @@ Returns the JSON representation used when this object is serialized.
Example
```ts -import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type'; +import { + GraphQLObjectType, + GraphQLString, + GraphQLUnionType, +} from 'graphql/type'; const Photo = new GraphQLObjectType({ name: 'Photo', @@ -3264,7 +3272,7 @@ const GeoPoint = new GraphQLInputObjectType({ lat: { type: new GraphQLNonNull(GraphQLFloat) }, lon: { type: new GraphQLNonNull(GraphQLFloat) }, alt: { type: GraphQLFloat, default: { value: 0 } }, - } + }, }); ``` @@ -4767,7 +4775,9 @@ Returns true when the value is a resolved GraphQL enum value definition. import { buildSchema } from 'graphql/utilities'; import { assertEnumType, isEnumValue } from 'graphql/type'; -const schema = buildSchema('enum Episode { NEW_HOPE } type Query { episode: Episode }'); +const schema = buildSchema( + 'enum Episode { NEW_HOPE } type Query { episode: Episode }', +); const enumValue = assertEnumType(schema.getType('Episode')).getValues()[0]; isEnumValue(enumValue); // => true @@ -4832,7 +4842,9 @@ Returns the value as a GraphQLEnumValue, or throws if it is not one. import { buildSchema } from 'graphql/utilities'; import { assertEnumType, assertEnumValue } from 'graphql/type'; -const schema = buildSchema('enum Episode { NEW_HOPE } type Query { episode: Episode }'); +const schema = buildSchema( + 'enum Episode { NEW_HOPE } type Query { episode: Episode }', +); const enumValue = assertEnumValue( assertEnumType(schema.getType('Episode')).getValues()[0], ); @@ -5053,8 +5065,12 @@ Returns true when the value is a resolved GraphQL input field definition. import { buildSchema } from 'graphql/utilities'; import { assertInputObjectType, isInputField } from 'graphql/type'; -const schema = buildSchema('input ReviewInput { stars: Int } type Query { ok: Boolean }'); -const inputField = assertInputObjectType(schema.getType('ReviewInput')).getFields().stars; +const schema = buildSchema( + 'input ReviewInput { stars: Int } type Query { ok: Boolean }', +); +const inputField = assertInputObjectType( + schema.getType('ReviewInput'), +).getFields().stars; isInputField(inputField); // => true isInputField(schema.getQueryType()); // => false @@ -5118,7 +5134,9 @@ Returns the value as a GraphQLInputField, or throws if it is not one. import { buildSchema } from 'graphql/utilities'; import { assertInputField, assertInputObjectType } from 'graphql/type'; -const schema = buildSchema('input ReviewInput { stars: Int } type Query { ok: Boolean }'); +const schema = buildSchema( + 'input ReviewInput { stars: Int } type Query { ok: Boolean }', +); const inputField = assertInputField( assertInputObjectType(schema.getType('ReviewInput')).getFields().stars, ); @@ -6908,9 +6926,7 @@ import { getNullableType, } from 'graphql/type'; -const requiredStringList = new GraphQLNonNull( - new GraphQLList(GraphQLString), -); +const requiredStringList = new GraphQLNonNull(new GraphQLList(GraphQLString)); getNullableType(requiredStringList).toString(); // => '[String]' getNullableType(GraphQLString); // => GraphQLString @@ -7357,11 +7373,7 @@ Returns the named type after unwrapping all list and non-null wrappers.
Example
```ts -import { - GraphQLList, - GraphQLString, - getNamedType, -} from 'graphql/type'; +import { GraphQLList, GraphQLString, getNamedType } from 'graphql/type'; getNamedType(new GraphQLList(GraphQLString)); // => GraphQLString getNamedType(undefined); // => undefined @@ -10114,7 +10126,11 @@ Returns a normalized configuration object for this input field.
Example
```ts -import { GraphQLInputField, GraphQLInputObjectType, GraphQLString } from 'graphql/type'; +import { + GraphQLInputField, + GraphQLInputObjectType, + GraphQLString, +} from 'graphql/type'; const ReviewInput = new GraphQLInputObjectType({ name: 'ReviewInput', @@ -10162,7 +10178,11 @@ Returns this input field as a schema coordinate string.
Example
```ts -import { GraphQLInputField, GraphQLInputObjectType, GraphQLString } from 'graphql/type'; +import { + GraphQLInputField, + GraphQLInputObjectType, + GraphQLString, +} from 'graphql/type'; const ReviewInput = new GraphQLInputObjectType({ name: 'ReviewInput', @@ -10209,7 +10229,11 @@ Returns the JSON representation used when this object is serialized.
Example
```ts -import { GraphQLInputField, GraphQLInputObjectType, GraphQLString } from 'graphql/type'; +import { + GraphQLInputField, + GraphQLInputObjectType, + GraphQLString, +} from 'graphql/type'; const ReviewInput = new GraphQLInputObjectType({ name: 'ReviewInput', diff --git a/website/pages/api-v17/utilities.mdx b/website/pages/api-v17/utilities.mdx index 552bea9dce..c8ebcc37df 100644 --- a/website/pages/api-v17/utilities.mdx +++ b/website/pages/api-v17/utilities.mdx @@ -1340,7 +1340,10 @@ const ReviewInput = new GraphQLInputObjectType({ }, }); -coerceInputLiteral(parseValue('{ stars: 5, comment: "Loved it" }'), ReviewInput); // => { stars: 5, comment: 'Loved it' } +coerceInputLiteral( + parseValue('{ stars: 5, comment: "Loved it" }'), + ReviewInput, +); // => { stars: 5, comment: 'Loved it' } coerceInputLiteral(parseValue('{ comment: "Missing" }'), ReviewInput); // => undefined ``` @@ -1363,11 +1366,9 @@ const schema = buildSchema(` `); const document = parse('query ($stars: Int = 5) { review(stars: $stars) }'); const operation = document.definitions[0]; -const result = getVariableValues( - schema, - operation.variableDefinitions, - { stars: '4' }, -); +const result = getVariableValues(schema, operation.variableDefinitions, { + stars: '4', +}); assert('variableValues' in result); @@ -1454,15 +1455,11 @@ const schema = buildSchema(` review(stars: Int = 5): String } `); -const document = parse( - 'query ($stars: Int = 5) { review(stars: $stars) }', -); +const document = parse('query ($stars: Int = 5) { review(stars: $stars) }'); const operation = document.definitions[0]; -const result = getVariableValues( - schema, - operation.variableDefinitions, - { stars: 4 }, -); +const result = getVariableValues(schema, operation.variableDefinitions, { + stars: 4, +}); assert('variableValues' in result); @@ -1968,9 +1965,13 @@ const ReviewInput = new GraphQLInputObjectType({ }); const errors = []; -validateInputLiteral(parseValue('{ stars: "bad" }'), ReviewInput, (error, path) => { - errors.push({ message: error.message, path }); -}); +validateInputLiteral( + parseValue('{ stars: "bad" }'), + ReviewInput, + (error, path) => { + errors.push({ message: error.message, path }); + }, +); errors; // => [ { message: 'Expected value of type "Int", found: "bad".', path: ['stars'] } ] ``` @@ -1994,11 +1995,9 @@ const schema = buildSchema(` `); const document = parse('query ($stars: Int = 5) { review(stars: $stars) }'); const operation = document.definitions[0]; -const result = getVariableValues( - schema, - operation.variableDefinitions, - { stars: '4' }, -); +const result = getVariableValues(schema, operation.variableDefinitions, { + stars: '4', +}); assert('variableValues' in result); @@ -2637,9 +2636,9 @@ const invalidExtension = parse(` extendSchema(schema, invalidExtension); // throws an error extendSchema(schema, invalidExtension, { - assumeValid: true, - assumeValidSDL: true, - }); // does not throw + assumeValid: true, + assumeValidSDL: true, +}); // does not throw ```
@@ -2699,7 +2698,11 @@ This function returns a sorted copy of the given GraphQLSchema.
Example
```ts -import { buildSchema, lexicographicSortSchema, printSchema } from 'graphql/utilities'; +import { + buildSchema, + lexicographicSortSchema, + printSchema, +} from 'graphql/utilities'; const schema = buildSchema(` type Query { @@ -2886,7 +2889,11 @@ the "errors" field of a server response before calling this function.
Example
```ts -import { buildClientSchema, introspectionFromSchema, buildSchema } from 'graphql/utilities'; +import { + buildClientSchema, + introspectionFromSchema, + buildSchema, +} from 'graphql/utilities'; const schema = buildSchema('type Query { hello: String }'); const clientSchema = buildClientSchema(introspectionFromSchema(schema), { @@ -3067,7 +3074,9 @@ const schema = buildSchema(` `); const introspection = introspectionFromSchema(schema); -const urlType = introspection.__schema.types.find((type) => type.name === 'Url'); +const urlType = introspection.__schema.types.find( + (type) => type.name === 'Url', +); urlType.specifiedByURL; // => 'https://url.spec.whatwg.org/' ``` @@ -3097,7 +3106,9 @@ const introspection = introspectionFromSchema(schema, { experimentalDirectiveDeprecation: false, oneOf: false, }); -const urlType = introspection.__schema.types.find((type) => type.name === 'Url'); +const urlType = introspection.__schema.types.find( + (type) => type.name === 'Url', +); const deprecatedDirective = introspection.__schema.directives.find( (directive) => directive.name === 'deprecated', ); @@ -4021,7 +4032,10 @@ GraphQL source files which together represent one conceptual application. import { parse } from 'graphql/language'; import { concatAST } from 'graphql/utilities'; -const document = concatAST([parse('type Query { a: String }'), parse('type User { id: ID }')]); +const document = concatAST([ + parse('type Query { a: String }'), + parse('type User { id: ID }'), +]); document.definitions.length; // => 2 ``` @@ -4195,7 +4209,7 @@ query SomeQuery($foo: String!, $bar: String) { Becomes: -```graphql +```graphql prettier-ignore query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){a b{c d}}} ``` @@ -4217,7 +4231,7 @@ type Foo { Becomes: -```graphql +```graphql prettier-ignore """Type description""" type Foo{"""Field description""" bar:String} ``` @@ -5183,7 +5197,11 @@ Prints a directive definition in GraphQL SDL.
Example
```ts -import { DirectiveLocation, GraphQLDirective, GraphQLString } from 'graphql/type'; +import { + DirectiveLocation, + GraphQLDirective, + GraphQLString, +} from 'graphql/type'; import { printDirective } from 'graphql/utilities'; const authDirective = new GraphQLDirective({ @@ -5464,11 +5482,7 @@ Provided two types, return true if the types are equal (invariant).
Example
```ts -import { - GraphQLList, - GraphQLNonNull, - GraphQLString, -} from 'graphql/type'; +import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type'; import { isEqualType } from 'graphql/utilities'; isEqualType(GraphQLString, GraphQLString); // => true diff --git a/website/pages/api-v17/validation.mdx b/website/pages/api-v17/validation.mdx index c6e926e3fb..a8a4bae7fe 100644 --- a/website/pages/api-v17/validation.mdx +++ b/website/pages/api-v17/validation.mdx @@ -1179,7 +1179,10 @@ A GraphQL document is only valid if defer directives are not used on root mutati ```ts import { parse } from 'graphql/language'; import { buildSchema } from 'graphql/utilities'; -import { validate, DeferStreamDirectiveOnRootFieldRule } from 'graphql/validation'; +import { + validate, + DeferStreamDirectiveOnRootFieldRule, +} from 'graphql/validation'; const schema = buildSchema(` type Query { @@ -1378,14 +1381,18 @@ const schema = buildSchema(` const invalidDocument = parse(` type Extra { field: String } `); -const invalidErrors = validate(schema, invalidDocument, [ExecutableDefinitionsRule]); +const invalidErrors = validate(schema, invalidDocument, [ + ExecutableDefinitionsRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { name } `); -const validErrors = validate(schema, validDocument, [ExecutableDefinitionsRule]); +const validErrors = validate(schema, validDocument, [ + ExecutableDefinitionsRule, +]); validErrors; // => [] ``` @@ -1462,7 +1469,9 @@ const schema = buildSchema(` const invalidDocument = parse(` { missing } `); -const invalidErrors = validate(schema, invalidDocument, [FieldsOnCorrectTypeRule]); +const invalidErrors = validate(schema, invalidDocument, [ + FieldsOnCorrectTypeRule, +]); invalidErrors.length; // => 1 @@ -1547,14 +1556,18 @@ const schema = buildSchema(` const invalidDocument = parse(` fragment Bad on String { length } `); -const invalidErrors = validate(schema, invalidDocument, [FragmentsOnCompositeTypesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + FragmentsOnCompositeTypesRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` fragment Good on Query { name } `); -const validErrors = validate(schema, validDocument, [FragmentsOnCompositeTypesRule]); +const validErrors = validate(schema, validDocument, [ + FragmentsOnCompositeTypesRule, +]); validErrors; // => [] ``` @@ -1632,7 +1645,9 @@ const schema = buildSchema(` const invalidDocument = parse(` { field(unknown: "1") } `); -const invalidErrors = validate(schema, invalidDocument, [KnownArgumentNamesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + KnownArgumentNamesRule, +]); invalidErrors.length; // => 1 @@ -1800,7 +1815,9 @@ const schema = buildSchema(` const invalidDocument = parse(` { ...Missing } `); -const invalidErrors = validate(schema, invalidDocument, [KnownFragmentNamesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + KnownFragmentNamesRule, +]); invalidErrors.length; // => 1 @@ -2044,14 +2061,18 @@ const schema = buildSchema(` const invalidDocument = parse(` query { name } query Other { name } `); -const invalidErrors = validate(schema, invalidDocument, [LoneAnonymousOperationRule]); +const invalidErrors = validate(schema, invalidDocument, [ + LoneAnonymousOperationRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { name } `); -const validErrors = validate(schema, validDocument, [LoneAnonymousOperationRule]); +const validErrors = validate(schema, validDocument, [ + LoneAnonymousOperationRule, +]); validErrors; // => [] ``` @@ -2197,14 +2218,18 @@ const schema = buildSchema(` const invalidDocument = parse(` { __schema { types { fields { type { fields { type { fields { name } } } } } } } } `); -const invalidErrors = validate(schema, invalidDocument, [MaxIntrospectionDepthRule]); +const invalidErrors = validate(schema, invalidDocument, [ + MaxIntrospectionDepthRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { __schema { queryType { name } } } `); -const validErrors = validate(schema, validDocument, [MaxIntrospectionDepthRule]); +const validErrors = validate(schema, validDocument, [ + MaxIntrospectionDepthRule, +]); validErrors; // => [] ``` @@ -2365,7 +2390,9 @@ const schema = buildSchema(` const invalidDocument = parse(` query ($id: ID) { field(arg: $missing) } `); -const invalidErrors = validate(schema, invalidDocument, [NoUndefinedVariablesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + NoUndefinedVariablesRule, +]); invalidErrors.length; // => 1 @@ -2449,7 +2476,9 @@ const schema = buildSchema(` const invalidDocument = parse(` fragment Unused on Query { name } query { name } `); -const invalidErrors = validate(schema, invalidDocument, [NoUnusedFragmentsRule]); +const invalidErrors = validate(schema, invalidDocument, [ + NoUnusedFragmentsRule, +]); invalidErrors.length; // => 1 @@ -2534,7 +2563,9 @@ const schema = buildSchema(` const invalidDocument = parse(` query ($id: ID) { name } `); -const invalidErrors = validate(schema, invalidDocument, [NoUnusedVariablesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + NoUnusedVariablesRule, +]); invalidErrors.length; // => 1 @@ -2624,14 +2655,18 @@ const schema = buildSchema(` const invalidDocument = parse(` { dog { value: barkVolume value: name } } `); -const invalidErrors = validate(schema, invalidDocument, [OverlappingFieldsCanBeMergedRule]); +const invalidErrors = validate(schema, invalidDocument, [ + OverlappingFieldsCanBeMergedRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { dog { barkVolume name } } `); -const validErrors = validate(schema, validDocument, [OverlappingFieldsCanBeMergedRule]); +const validErrors = validate(schema, validDocument, [ + OverlappingFieldsCanBeMergedRule, +]); validErrors; // => [] ``` @@ -2715,14 +2750,18 @@ const schema = buildSchema(` const invalidDocument = parse(` { dog { ... on Cat { meowVolume } } } `); -const invalidErrors = validate(schema, invalidDocument, [PossibleFragmentSpreadsRule]); +const invalidErrors = validate(schema, invalidDocument, [ + PossibleFragmentSpreadsRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { dog { ... on Dog { barkVolume } } } `); -const validErrors = validate(schema, validDocument, [PossibleFragmentSpreadsRule]); +const validErrors = validate(schema, validDocument, [ + PossibleFragmentSpreadsRule, +]); validErrors; // => [] ``` @@ -2871,14 +2910,18 @@ const schema = buildSchema(` const invalidDocument = parse(` { field } `); -const invalidErrors = validate(schema, invalidDocument, [ProvidedRequiredArgumentsRule]); +const invalidErrors = validate(schema, invalidDocument, [ + ProvidedRequiredArgumentsRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { field(required: "x") } `); -const validErrors = validate(schema, validDocument, [ProvidedRequiredArgumentsRule]); +const validErrors = validate(schema, validDocument, [ + ProvidedRequiredArgumentsRule, +]); validErrors; // => [] ``` @@ -3042,14 +3085,18 @@ const schema = buildSchema(` const invalidDocument = parse(` subscription { a b } `); -const invalidErrors = validate(schema, invalidDocument, [SingleFieldSubscriptionsRule]); +const invalidErrors = validate(schema, invalidDocument, [ + SingleFieldSubscriptionsRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` subscription { a } `); -const validErrors = validate(schema, validDocument, [SingleFieldSubscriptionsRule]); +const validErrors = validate(schema, validDocument, [ + SingleFieldSubscriptionsRule, +]); validErrors; // => [] ``` @@ -3275,7 +3322,9 @@ const schema = buildSchema(` const invalidDocument = parse(` { field(arg: "1", arg: "2") } `); -const invalidErrors = validate(schema, invalidDocument, [UniqueArgumentNamesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + UniqueArgumentNamesRule, +]); invalidErrors.length; // => 1 @@ -3433,14 +3482,18 @@ const schema = buildSchema(` const invalidDocument = parse(` { name @include(if: true) @include(if: false) } `); -const invalidErrors = validate(schema, invalidDocument, [UniqueDirectivesPerLocationRule]); +const invalidErrors = validate(schema, invalidDocument, [ + UniqueDirectivesPerLocationRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { name @include(if: true) } `); -const validErrors = validate(schema, validDocument, [UniqueDirectivesPerLocationRule]); +const validErrors = validate(schema, validDocument, [ + UniqueDirectivesPerLocationRule, +]); validErrors; // => [] ``` @@ -3664,7 +3717,9 @@ const schema = buildSchema(` const invalidDocument = parse(` fragment A on Query { name } fragment A on Query { name } query { ...A } `); -const invalidErrors = validate(schema, invalidDocument, [UniqueFragmentNamesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + UniqueFragmentNamesRule, +]); invalidErrors.length; // => 1 @@ -3752,14 +3807,18 @@ const schema = buildSchema(` const invalidDocument = parse(` { search(filter: { name: "a", name: "b" }) } `); -const invalidErrors = validate(schema, invalidDocument, [UniqueInputFieldNamesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + UniqueInputFieldNamesRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { search(filter: { name: "a" }) } `); -const validErrors = validate(schema, validDocument, [UniqueInputFieldNamesRule]); +const validErrors = validate(schema, validDocument, [ + UniqueInputFieldNamesRule, +]); validErrors; // => [] ``` @@ -3835,7 +3894,9 @@ const schema = buildSchema(` const invalidDocument = parse(` query Same { name } query Same { name } `); -const invalidErrors = validate(schema, invalidDocument, [UniqueOperationNamesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + UniqueOperationNamesRule, +]); invalidErrors.length; // => 1 @@ -4064,7 +4125,9 @@ const schema = buildSchema(` const invalidDocument = parse(` query ($id: ID, $id: ID) { field(arg: $id) } `); -const invalidErrors = validate(schema, invalidDocument, [UniqueVariableNamesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + UniqueVariableNamesRule, +]); invalidErrors.length; // => 1 @@ -4148,7 +4211,9 @@ const schema = buildSchema(` const invalidDocument = parse(` { count(limit: "many") } `); -const invalidErrors = validate(schema, invalidDocument, [ValuesOfCorrectTypeRule]); +const invalidErrors = validate(schema, invalidDocument, [ + ValuesOfCorrectTypeRule, +]); invalidErrors.length; // => 1 @@ -4236,14 +4301,18 @@ const schema = buildSchema(` const invalidDocument = parse(` query ($user: User) { field(arg: "1") } `); -const invalidErrors = validate(schema, invalidDocument, [VariablesAreInputTypesRule]); +const invalidErrors = validate(schema, invalidDocument, [ + VariablesAreInputTypesRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` query ($id: ID) { field(arg: $id) } `); -const validErrors = validate(schema, validDocument, [VariablesAreInputTypesRule]); +const validErrors = validate(schema, validDocument, [ + VariablesAreInputTypesRule, +]); validErrors; // => [] ``` @@ -4319,14 +4388,18 @@ const schema = buildSchema(` const invalidDocument = parse(` query ($id: String) { field(arg: $id) } `); -const invalidErrors = validate(schema, invalidDocument, [VariablesInAllowedPositionRule]); +const invalidErrors = validate(schema, invalidDocument, [ + VariablesInAllowedPositionRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` query ($id: ID!) { field(arg: $id) } `); -const validErrors = validate(schema, validDocument, [VariablesInAllowedPositionRule]); +const validErrors = validate(schema, validDocument, [ + VariablesInAllowedPositionRule, +]); validErrors; // => [] ``` @@ -4457,7 +4530,9 @@ const schema = new GraphQLSchema({ const invalidDocument = parse(` { oldName } `); -const invalidErrors = validate(schema, invalidDocument, [NoDeprecatedCustomRule]); +const invalidErrors = validate(schema, invalidDocument, [ + NoDeprecatedCustomRule, +]); invalidErrors.length; // => 1 @@ -4543,14 +4618,18 @@ const schema = buildSchema(` const invalidDocument = parse(` { __schema { queryType { name } } } `); -const invalidErrors = validate(schema, invalidDocument, [NoSchemaIntrospectionCustomRule]); +const invalidErrors = validate(schema, invalidDocument, [ + NoSchemaIntrospectionCustomRule, +]); invalidErrors.length; // => 1 const validDocument = parse(` { name } `); -const validErrors = validate(schema, validDocument, [NoSchemaIntrospectionCustomRule]); +const validErrors = validate(schema, validDocument, [ + NoSchemaIntrospectionCustomRule, +]); validErrors; // => [] ``` @@ -4691,12 +4770,9 @@ const schema = buildSchema(` `); const document = parse('{ missingOne missingTwo }'); -const errors = validate( - schema, - document, - [FieldsOnCorrectTypeRule], - { maxErrors: 1 }, -); +const errors = validate(schema, document, [FieldsOnCorrectTypeRule], { + maxErrors: 1, +}); errors.length; // => 2 errors[1].message; // => 'Too many validation errors, error limit reached. Validation aborted.'