Skip to content

Commit 1bb3f67

Browse files
committed
docs: align JSDoc examples with SDL config
1 parent c993b6b commit 1bb3f67

14 files changed

Lines changed: 512 additions & 372 deletions

File tree

src/execution/execute.ts

Lines changed: 84 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,28 @@ export type RootSelectionSetExecutor = (
9494
* import { buildSchema } from 'graphql/utilities';
9595
* import { execute } from 'graphql/execution';
9696
*
97-
* const schema = buildSchema(`
98-
* type Query {
99-
* greeting(name: String!): String
100-
* }
101-
* `);
97+
* const schema = buildSchema(
98+
* `
99+
* type Query {
100+
* greeting(name: String!): String
101+
* }
102+
* `,
103+
* {
104+
* supplementalConfig: {
105+
* objectTypes: {
106+
* Query: {
107+
* fields: {
108+
* greeting: (_source, { name }) => `Hello, ${name}!`,
109+
* },
110+
* },
111+
* },
112+
* },
113+
* },
114+
* );
102115
*
103116
* const result = await execute({
104117
* schema,
105118
* document: parse('query ($name: String!) { greeting(name: $name) }'),
106-
* rootValue: {
107-
* greeting: ({ name }) => `Hello, ${name}!`,
108-
* },
109119
* variableValues: { name: 'Ada' },
110120
* });
111121
*
@@ -185,16 +195,28 @@ function executeImpl(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
185195
* import { buildSchema } from 'graphql/utilities';
186196
* import { experimentalExecuteIncrementally } from 'graphql/execution';
187197
*
188-
* const schema = buildSchema(`
189-
* type Query {
190-
* greeting: String
191-
* }
192-
* `);
198+
* const schema = buildSchema(
199+
* `
200+
* type Query {
201+
* greeting: String
202+
* }
203+
* `,
204+
* {
205+
* supplementalConfig: {
206+
* objectTypes: {
207+
* Query: {
208+
* fields: {
209+
* greeting: () => 'Hello',
210+
* },
211+
* },
212+
* },
213+
* },
214+
* },
215+
* );
193216
*
194217
* const result = await experimentalExecuteIncrementally({
195218
* schema,
196219
* document: parse('{ greeting }'),
197-
* rootValue: { greeting: 'Hello' },
198220
* });
199221
*
200222
* result; // => { data: { greeting: 'Hello' } }
@@ -455,7 +477,6 @@ export function executeSubscriptionEvent(
455477
* @returns A response stream for a valid subscription, or an execution result containing errors.
456478
* @example
457479
* ```ts
458-
* // Use a same-named rootValue function to provide the source event stream.
459480
* import assert from 'node:assert';
460481
* import { parse } from 'graphql/language';
461482
* import { buildSchema } from 'graphql/utilities';
@@ -466,20 +487,34 @@ export function executeSubscriptionEvent(
466487
* yield { greeting: 'Bonjour' };
467488
* }
468489
*
469-
* const schema = buildSchema(`
470-
* type Query {
471-
* noop: String
472-
* }
473-
*
474-
* type Subscription {
475-
* greeting: String
476-
* }
477-
* `);
490+
* const schema = buildSchema(
491+
* `
492+
* type Query {
493+
* noop: String
494+
* }
495+
*
496+
* type Subscription {
497+
* greeting: String
498+
* }
499+
* `,
500+
* {
501+
* supplementalConfig: {
502+
* objectTypes: {
503+
* Subscription: {
504+
* fields: {
505+
* greeting: {
506+
* subscribe: () => greetings(),
507+
* },
508+
* },
509+
* },
510+
* },
511+
* },
512+
* },
513+
* );
478514
*
479515
* const result = await subscribe({
480516
* schema,
481517
* document: parse('subscription { greeting }'),
482-
* rootValue: { greeting: () => greetings() },
483518
* });
484519
*
485520
* assert('next' in result);
@@ -627,19 +662,33 @@ function subscribeImpl(
627662
* yield { greeting: 'Hello' };
628663
* }
629664
*
630-
* const schema = buildSchema(`
631-
* type Query {
632-
* noop: String
633-
* }
634-
*
635-
* type Subscription {
636-
* greeting: String
637-
* }
638-
* `);
665+
* const schema = buildSchema(
666+
* `
667+
* type Query {
668+
* noop: String
669+
* }
670+
*
671+
* type Subscription {
672+
* greeting: String
673+
* }
674+
* `,
675+
* {
676+
* supplementalConfig: {
677+
* objectTypes: {
678+
* Subscription: {
679+
* fields: {
680+
* greeting: {
681+
* subscribe: () => greetings(),
682+
* },
683+
* },
684+
* },
685+
* },
686+
* },
687+
* },
688+
* );
639689
* const validatedArgs = validateSubscriptionArgs({
640690
* schema,
641691
* document: parse('subscription { greeting }'),
642-
* rootValue: { greeting: () => greetings() },
643692
* });
644693
*
645694
* assert('schema' in validatedArgs);

src/graphql.ts

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,28 @@ export interface GraphQLArgs
6666
* // Execute a complete asynchronous request with variables.
6767
* import { graphql, buildSchema } from 'graphql';
6868
*
69-
* const schema = buildSchema(`
70-
* type Query {
71-
* greeting(name: String!): String
72-
* }
73-
* `);
69+
* const schema = buildSchema(
70+
* `
71+
* type Query {
72+
* greeting(name: String!): String
73+
* }
74+
* `,
75+
* {
76+
* supplementalConfig: {
77+
* objectTypes: {
78+
* Query: {
79+
* fields: {
80+
* greeting: (_source, { name }) => `Hello, ${name}!`,
81+
* },
82+
* },
83+
* },
84+
* },
85+
* },
86+
* );
7487
*
7588
* const result = await graphql({
7689
* schema,
7790
* source: 'query SayHello($name: String!) { greeting(name: $name) }',
78-
* rootValue: {
79-
* greeting: ({ name }) => `Hello, ${name}!`,
80-
* },
8191
* variableValues: { name: 'Ada' },
8292
* operationName: 'SayHello',
8393
* });
@@ -124,11 +134,24 @@ export interface GraphQLArgs
124134
* // This variant customizes the request pipeline with a harness.
125135
* import { buildSchema, defaultHarness, graphql } from 'graphql';
126136
*
127-
* const schema = buildSchema(`
128-
* type Query {
129-
* greeting: String
130-
* }
131-
* `);
137+
* const schema = buildSchema(
138+
* `
139+
* type Query {
140+
* greeting: String
141+
* }
142+
* `,
143+
* {
144+
* supplementalConfig: {
145+
* objectTypes: {
146+
* Query: {
147+
* fields: {
148+
* greeting: () => 'Hello',
149+
* },
150+
* },
151+
* },
152+
* },
153+
* },
154+
* );
132155
* const stages = [];
133156
* const abortController = new AbortController();
134157
* const harness = {
@@ -153,7 +176,6 @@ export interface GraphQLArgs
153176
* const result = await graphql({
154177
* schema,
155178
* source: '{ greeting }',
156-
* rootValue: { greeting: 'Hello' },
157179
* rules: [],
158180
* maxErrors: 25,
159181
* hideSuggestions: true,
@@ -186,18 +208,28 @@ export function graphql(args: GraphQLArgs): Promise<ExecutionResult> {
186208
* // Execute a complete synchronous request with variables.
187209
* import { graphqlSync, buildSchema } from 'graphql';
188210
*
189-
* const schema = buildSchema(`
190-
* type Query {
191-
* greeting(name: String!): String
192-
* }
193-
* `);
211+
* const schema = buildSchema(
212+
* `
213+
* type Query {
214+
* greeting(name: String!): String
215+
* }
216+
* `,
217+
* {
218+
* supplementalConfig: {
219+
* objectTypes: {
220+
* Query: {
221+
* fields: {
222+
* greeting: (_source, { name }) => `Hello, ${name}!`,
223+
* },
224+
* },
225+
* },
226+
* },
227+
* },
228+
* );
194229
*
195230
* const result = graphqlSync({
196231
* schema,
197232
* source: 'query SayHello($name: String!) { greeting(name: $name) }',
198-
* rootValue: {
199-
* greeting: ({ name }) => `Hello, ${name}!`,
200-
* },
201233
* variableValues: { name: 'Ada' },
202234
* operationName: 'SayHello',
203235
* });

src/type/scalars.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,20 @@ export const specifiedScalarTypes: ReadonlyArray<GraphQLScalarType> =
335335
* @example
336336
* ```ts
337337
* import {
338-
* GraphQLScalarType,
338+
* assertScalarType,
339339
* GraphQLString,
340340
* isSpecifiedScalarType,
341341
* } from 'graphql/type';
342+
* import { buildSchema } from 'graphql/utilities';
342343
*
343-
* const DateTime = new GraphQLScalarType({
344-
* name: 'DateTime',
345-
* });
344+
* const schema = buildSchema(`
345+
* scalar DateTime
346+
*
347+
* type Query {
348+
* now: DateTime
349+
* }
350+
* `);
351+
* const DateTime = assertScalarType(schema.getType('DateTime'));
346352
*
347353
* isSpecifiedScalarType(GraphQLString); // => true
348354
* isSpecifiedScalarType(DateTime); // => false

src/utilities/astFromValue.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,23 @@ import { GraphQLID } from '../type/scalars.ts';
4747
* ```ts
4848
* import { print } from 'graphql/language';
4949
* import {
50-
* GraphQLInputObjectType,
51-
* GraphQLInt,
52-
* GraphQLList,
50+
* assertInputObjectType,
5351
* GraphQLNonNull,
5452
* GraphQLString,
5553
* } from 'graphql/type';
56-
* import { astFromValue } from 'graphql/utilities';
54+
* import { astFromValue, buildSchema } from 'graphql/utilities';
5755
*
58-
* const ReviewInput = new GraphQLInputObjectType({
59-
* name: 'ReviewInput',
60-
* fields: {
61-
* stars: { type: new GraphQLNonNull(GraphQLInt) },
62-
* tags: { type: new GraphQLList(GraphQLString) },
63-
* },
64-
* });
56+
* const schema = buildSchema(`
57+
* input ReviewInput {
58+
* stars: Int!
59+
* tags: [String]
60+
* }
61+
*
62+
* type Query {
63+
* reviews(filter: ReviewInput): [String]
64+
* }
65+
* `);
66+
* const ReviewInput = assertInputObjectType(schema.getType('ReviewInput'));
6567
*
6668
* const valueNode = astFromValue(
6769
* { stars: 5, tags: ['featured', 'verified'] },

0 commit comments

Comments
 (0)