Skip to content

docs: fix incorrect API doc examples and copy-pasted descriptions - #4860

Open
Cito wants to merge 1 commit into
graphql:17.x.xfrom
Cito:docs/fix-api-doc-examples
Open

Cito wants to merge 1 commit into
graphql:17.x.xfrom
Cito:docs/fix-api-doc-examples

Conversation

@Cito

@Cito Cito commented Sep 27, 2026

Copy link
Copy Markdown
Member

While porting the new API docs to GraphQL-core (the Python port), every @example was run as a doctest. That turned up a few examples that don't produce what their // => comments say, and some descriptions that were copied from a different API. This PR fixes them.

Examples

  • validation/validate.ts: the schema defined fullName, but the example validated { greeting } and expected no errors; the schema now defines greeting.
  • type/definition.ts (GraphQLEnumType.valueToLiteral): the example passed the internal value 2, but the method takes the external value name, so it returned undefined and print() threw; now valueToLiteral('BLUE'). The summary and @param said "runtime enum value" and now say "external enum value name".
  • type/directives.ts (GraphQLDirective): extend directive @cacheControl(maxAge: Int) on FIELD_DEFINITION is a syntax error because directive extensions can only add directives; now extend directive @cacheControl @tag.
  • utilities/findSchemaChanges.ts: the result order was reversed; the function returns ['FIELD_ADDED', 'OPTIONAL_ARG_ADDED'].
  • utilities/coerceInputValue.ts, execution/values.ts (coerceInputValue, coerceInputLiteral, getVariableValues, getArgumentValues): the examples passed '5'/'4' for Int inputs, which yields undefined or coercion errors instead of the documented values; they now pass numbers.
  • utilities/TypeInfo.ts (leave): after leaving the field, getType() returns the parent type Query, not undefined; the @param also said "being entered".
  • utilities/buildASTSchema.ts (buildSchema): @tag was applied to a directive definition but declared on FIELD_DEFINITION, so schema validation failed; it is now declared on DIRECTIVE_DEFINITION.
  • validation/rules/custom/NoSchemaIntrospectionCustomRule.ts: { __schema { queryType { name } } } reports 2 errors (__schema and queryType), not 1.

Descriptions

  • validation/rules/DeferStreamDirectiveOnValidOperationsRule.ts: the summary was copied from DeferStreamDirectiveOnRootFieldRule; the rule actually forbids @defer/@stream in subscription operations unless they can be disabled or skipped.
  • language/ast.ts (FragmentArgumentNode): described as a variable definition with a default value, but it is an argument supplied on a fragment spread (...Frag(arg: value)).
  • type/definition.ts (GraphQLResolveInfo): fieldName, path and schema had descriptions from other APIs ("referenced by this schema coordinate", "where this error occurred", "used for validation or execution").
  • utilities/getIntrospectionQuery.ts (IntrospectionSchema.types) and type/schema.ts (GraphQLSchemaConfig.types): both said "Object types that belong to this union type".

Every changed example was executed against this branch, and each // => comment now matches the actual result. Before this change, 11 of those example blocks failed or threw.

The fixes in directives.ts, coerceInputValue.ts, values.ts, TypeInfo.ts, buildASTSchema.ts, NoSchemaIntrospectionCustomRule.ts, GraphQLResolveInfo, getIntrospectionQuery.ts and schema.ts also apply to the same text on 16.x.x and could be backported.

It might be worth running the @example blocks in CI to catch such drift automatically. At the moment prettier:examples:check only formats them.

Fix @example blocks whose `// =>` results don't match what the code
actually returns, and property descriptions that were copied from
unrelated APIs.
@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

@Cito is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@Cito
Cito marked this pull request as ready for review September 27, 2026 15:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant