Skip to content

Commit 22af985

Browse files
chore(deps): lock file maintenance (#7282)
* chore(deps): lock file maintenance * Fix sharp * oneOf support * Fix v15 support * Relax type check on v15 * Better --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
1 parent 53db005 commit 22af985

File tree

5 files changed

+410
-352
lines changed

5 files changed

+410
-352
lines changed

.changeset/olive-plants-bet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': patch
3+
---
4+
5+
Support `@oneOf` directive

packages/utils/src/print-schema-with-directives.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
ScalarTypeDefinitionNode,
4242
SchemaDefinitionNode,
4343
SchemaExtensionNode,
44+
specifiedDirectives,
4445
UnionTypeDefinitionNode,
4546
ValueNode,
4647
} from 'graphql';
@@ -219,11 +220,12 @@ export function getDirectiveNodes<TDirectiveNode extends DirectiveNode>(
219220
deprecationReason?: string | null;
220221
specifiedByUrl?: string | null;
221222
specifiedByURL?: string | null;
223+
isOneOf?: boolean;
222224
},
223225
schema?: GraphQLSchema,
224226
pathToDirectivesInExtensions?: Array<string>,
225227
): Array<TDirectiveNode> {
226-
let directiveNodesBesidesDeprecatedAndSpecifiedBy: Array<TDirectiveNode> = [];
228+
let directiveNodesBesidesNativeDirectives: Array<TDirectiveNode> = [];
227229

228230
const directivesInExtensions = getDirectivesInExtensions(entity, pathToDirectivesInExtensions);
229231

@@ -234,19 +236,23 @@ export function getDirectiveNodes<TDirectiveNode extends DirectiveNode>(
234236

235237
let deprecatedDirectiveNode: Maybe<TDirectiveNode> = null;
236238
let specifiedByDirectiveNode: Maybe<TDirectiveNode> = null;
239+
let oneOfDirectiveNode: Maybe<TDirectiveNode> = null;
237240
if (directives != null) {
238-
directiveNodesBesidesDeprecatedAndSpecifiedBy = directives.filter(
239-
directive => directive.name.value !== 'deprecated' && directive.name.value !== 'specifiedBy',
241+
directiveNodesBesidesNativeDirectives = directives.filter(directive =>
242+
specifiedDirectives.every(
243+
specifiedDirective => specifiedDirective.name !== directive.name.value,
244+
),
240245
);
241246
if (entity.deprecationReason != null) {
242-
deprecatedDirectiveNode = directives.filter(
243-
directive => directive.name.value === 'deprecated',
244-
)?.[0];
247+
deprecatedDirectiveNode = directives.find(directive => directive.name.value === 'deprecated');
245248
}
246249
if (entity.specifiedByUrl != null || entity.specifiedByURL != null) {
247-
specifiedByDirectiveNode = directives.filter(
250+
specifiedByDirectiveNode = directives.find(
248251
directive => directive.name.value === 'specifiedBy',
249-
)?.[0];
252+
);
253+
}
254+
if (entity.isOneOf) {
255+
oneOfDirectiveNode = directives.find(directive => directive.name.value === 'oneOf');
250256
}
251257
}
252258

@@ -265,13 +271,20 @@ export function getDirectiveNodes<TDirectiveNode extends DirectiveNode>(
265271
specifiedByDirectiveNode = makeDirectiveNode<TDirectiveNode>('specifiedBy', specifiedByArgs);
266272
}
267273

274+
if (entity.isOneOf && oneOfDirectiveNode == null) {
275+
oneOfDirectiveNode = makeDirectiveNode<TDirectiveNode>('oneOf');
276+
}
277+
268278
if (deprecatedDirectiveNode != null) {
269-
directiveNodesBesidesDeprecatedAndSpecifiedBy.push(deprecatedDirectiveNode);
279+
directiveNodesBesidesNativeDirectives.push(deprecatedDirectiveNode);
270280
}
271281
if (specifiedByDirectiveNode != null) {
272-
directiveNodesBesidesDeprecatedAndSpecifiedBy.push(specifiedByDirectiveNode);
282+
directiveNodesBesidesNativeDirectives.push(specifiedByDirectiveNode);
283+
}
284+
if (oneOfDirectiveNode != null) {
285+
directiveNodesBesidesNativeDirectives.push(oneOfDirectiveNode);
273286
}
274-
return directiveNodesBesidesDeprecatedAndSpecifiedBy;
287+
return directiveNodesBesidesNativeDirectives;
275288
}
276289

277290
export function astFromArg(

packages/utils/tests/print-schema-with-directives.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import {
33
GraphQLDirective,
44
GraphQLEnumType,
55
GraphQLID,
6+
GraphQLInputObjectType,
7+
GraphQLInputObjectTypeConfig,
8+
GraphQLInt,
69
GraphQLList,
710
GraphQLNonNull,
811
GraphQLObjectType,
912
GraphQLSchema,
13+
GraphQLString,
1014
printSchema,
1115
specifiedDirectives,
1216
} from 'graphql';
@@ -371,4 +375,31 @@ describe('printSchemaWithDirectives', () => {
371375
expect(printedSchema).toContain(line.trim());
372376
}
373377
});
378+
it(`prints oneOf correctly if they don't have astNode`, () => {
379+
const oneOfInputType = new GraphQLInputObjectType({
380+
name: 'OneOfInput',
381+
isOneOf: true,
382+
fields: {
383+
a: {
384+
type: GraphQLString,
385+
},
386+
b: {
387+
type: GraphQLInt,
388+
},
389+
},
390+
} as GraphQLInputObjectTypeConfig);
391+
// Only if `isOneOf` is supported, it should print the directive
392+
if ((oneOfInputType as any).isOneOf) {
393+
const schema = new GraphQLSchema({
394+
query: new GraphQLObjectType({
395+
name: 'Query',
396+
fields: {},
397+
}),
398+
types: [oneOfInputType],
399+
});
400+
401+
const output = printSchemaWithDirectives(schema);
402+
expect(output).toContain('input OneOfInput @oneOf');
403+
}
404+
});
374405
});

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"postcss": "8.5.6",
2929
"postcss-import": "16.1.1",
3030
"postcss-lightningcss": "1.0.1",
31+
"sharp": "0.34.3",
3132
"tailwindcss": "3.4.17",
3233
"typescript": "5.8.3",
3334
"wrangler": "4.24.3"

0 commit comments

Comments
 (0)