From 9032db1e4e55052bead6936359ecc5592c817f64 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 1 Jul 2025 03:59:08 +0200 Subject: [PATCH 1/3] Fix navigation (#4444) --- website/pages/docs/_meta.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/pages/docs/_meta.ts b/website/pages/docs/_meta.ts index 0ac35a9b41..3ad0f1dd42 100644 --- a/website/pages/docs/_meta.ts +++ b/website/pages/docs/_meta.ts @@ -36,7 +36,8 @@ const meta = { 'resolver-anatomy': '', 'graphql-errors': '', 'using-directives': '', - '-- 3': { + 'authorization-strategies': '', + '-- 4': { type: 'separator', title: 'Testing', }, @@ -45,8 +46,7 @@ const meta = { 'testing-operations': '', 'testing-resolvers': '', 'testing-best-practices': '', - 'authorization-strategies': '', - '-- 4': { + '-- 5': { type: 'separator', title: 'Production & Scaling', }, From 7134cab194b259dba123a2b18c9c39215513d83a Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Mon, 7 Jul 2025 17:36:36 +0200 Subject: [PATCH 2/3] Remove oneof validation from values of correct type (#4453) Supersedes https://github.com/graphql/graphql-js/pull/4445 Fixes https://github.com/graphql/graphql-js/issues/4443 `VariablesInAllowedPositionRule` already validates this --- .../__tests__/ValuesOfCorrectTypeRule-test.ts | 16 ------------ .../VariablesInAllowedPositionRule-test.ts | 10 +++++++ .../rules/ValuesOfCorrectTypeRule.ts | 26 +------------------ 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts b/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts index 3610fa648b..6f7697a694 100644 --- a/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts +++ b/src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts @@ -1094,22 +1094,6 @@ describe('Validate: Values of correct type', () => { ]); }); - it('Exactly one nullable variable', () => { - expectErrors(` - query ($string: String) { - complicatedArgs { - oneOfArgField(oneOfArg: { stringField: $string }) - } - } - `).toDeepEqual([ - { - message: - 'Variable "string" must be non-nullable to be used for OneOf Input Object "OneOfInput".', - locations: [{ line: 4, column: 37 }], - }, - ]); - }); - it('More than one field', () => { expectErrors(` { diff --git a/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts b/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts index 6fc3d59c39..ec839d7497 100644 --- a/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts +++ b/src/validation/__tests__/VariablesInAllowedPositionRule-test.ts @@ -370,6 +370,16 @@ describe('Validates OneOf Input Objects', () => { `); }); + it('Undefined variable in oneOf input object', () => { + expectErrors(` + { + complicatedArgs { + oneOfArgField(oneOfArg: { stringField: $undefinedVariable }) + } + } + `).toDeepEqual([]); + }); + it('Forbids one nullable variable', () => { expectErrors(` query ($string: String) { diff --git a/src/validation/rules/ValuesOfCorrectTypeRule.ts b/src/validation/rules/ValuesOfCorrectTypeRule.ts index 3f284d7103..6636e6a552 100644 --- a/src/validation/rules/ValuesOfCorrectTypeRule.ts +++ b/src/validation/rules/ValuesOfCorrectTypeRule.ts @@ -82,13 +82,7 @@ export function ValuesOfCorrectTypeRule( } if (type.isOneOf) { - validateOneOfInputObject( - context, - node, - type, - fieldNodeMap, - variableDefinitions, - ); + validateOneOfInputObject(context, node, type, fieldNodeMap); } }, ObjectField(node) { @@ -185,7 +179,6 @@ function validateOneOfInputObject( node: ObjectValueNode, type: GraphQLInputObjectType, fieldNodeMap: ObjMap, - variableDefinitions: { [key: string]: VariableDefinitionNode }, ): void { const keys = Object.keys(fieldNodeMap); const isNotExactlyOneField = keys.length !== 1; @@ -202,7 +195,6 @@ function validateOneOfInputObject( const value = fieldNodeMap[keys[0]]?.value; const isNullLiteral = !value || value.kind === Kind.NULL; - const isVariable = value?.kind === Kind.VARIABLE; if (isNullLiteral) { context.reportError( @@ -210,21 +202,5 @@ function validateOneOfInputObject( nodes: [node], }), ); - return; - } - - if (isVariable) { - const variableName = value.name.value; - const definition = variableDefinitions[variableName]; - const isNullableVariable = definition.type.kind !== Kind.NON_NULL_TYPE; - - if (isNullableVariable) { - context.reportError( - new GraphQLError( - `Variable "${variableName}" must be non-nullable to be used for OneOf Input Object "${type.name}".`, - { nodes: [node] }, - ), - ); - } } } From 8dc295551f9a64276442ef850943794db6bcaa4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Culek?= Date: Tue, 8 Jul 2025 09:16:36 +0200 Subject: [PATCH 3/3] fix(docs/mutations-and-input-types.mdx): root being inside of SDL (#4452) The example shows graphql implementation, where the "root" is by mistake put as string as part of the schema definition instead being a native js const BEFORE (root is undefined and wongly put into the schema itself): ![image](https://github.com/user-attachments/assets/3908e84e-1c3e-43b5-8633-163ea66fdfa0) AFTER (root correctly defined outside of the schema): ![image](https://github.com/user-attachments/assets/e14d51cc-2f36-450d-aea8-384d6c6a0703) --- .../pages/docs/mutations-and-input-types.mdx | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/website/pages/docs/mutations-and-input-types.mdx b/website/pages/docs/mutations-and-input-types.mdx index 397ff64f21..8948c69b34 100644 --- a/website/pages/docs/mutations-and-input-types.mdx +++ b/website/pages/docs/mutations-and-input-types.mdx @@ -230,26 +230,6 @@ type Query { getMessages: [Message] } -const root = { - getMessage: ({ id }) => { - return fakeDatabase[id] - }, - getMessages: () => { - return Object.values(fakeDatabase) - }, - createMessage: ({ input }) => { - const id = String(Object.keys(fakeDatabase).length + 1) - const message = new Message(id, input) - fakeDatabase[id] = message - return message - }, - updateMessage: ({ id, input }) => { - const message = fakeDatabase[id] - Object.assign(message, input) - return message - } -} - type Mutation { createMessage(input: MessageInput): Message updateMessage(id: ID!, input: MessageInput): Message @@ -265,6 +245,26 @@ class Message { } } +const root = { + getMessage: ({ id }) => { + return fakeDatabase[id] + }, + getMessages: () => { + return Object.values(fakeDatabase) + }, + createMessage: ({ input }) => { + const id = String(Object.keys(fakeDatabase).length + 1) + const message = new Message(id, input) + fakeDatabase[id] = message + return message + }, + updateMessage: ({ id, input }) => { + const message = fakeDatabase[id] + Object.assign(message, input) + return message + } +} + const app = express(); app.all( '/graphql',