Browse Source

fix(core): Fix error in validating custom fields with introspection fields in query

Fixes #1091
Filip Prochazka 4 years ago
parent
commit
f8564918f9

+ 18 - 0
packages/core/e2e/custom-fields.e2e-spec.ts

@@ -662,6 +662,24 @@ describe('Custom fields', () => {
                 `);
             }, `relation error`),
         );
+
+        // https://github.com/vendure-ecommerce/vendure/issues/1091
+        it('handles well graphql internal fields', async () => {
+            // throws "Cannot read property 'args' of undefined" if broken
+            await adminClient.query(gql`
+                mutation {
+                    __typename
+                    updateProduct(input: { id: "T_1", customFields: { nullable: "some value" } }) {
+                        __typename
+                        id
+                        customFields {
+                            __typename
+                            nullable
+                        }
+                    }
+                }
+            `);
+        });
     });
 
     describe('public access', () => {

+ 3 - 0
packages/core/src/api/middleware/validate-custom-fields-interceptor.ts

@@ -129,7 +129,10 @@ export class ValidateCustomFieldsInterceptor implements NestInterceptor {
         for (const selection of operation.selectionSet.selections) {
             if (selection.kind === 'Field') {
                 const name = selection.name.value;
+
                 const inputType = mutationType.getFields()[name];
+                if (!inputType) continue;
+
                 for (const arg of inputType.args) {
                     map[arg.name] = this.getInputTypeName(arg.type);
                 }