Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1091 #1178

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/core/e2e/custom-fields.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class ValidateCustomFieldsInterceptor implements NestInterceptor {
const map: { [inputName: string]: string } = {};

for (const selection of operation.selectionSet.selections) {
if (selection.kind === 'Field') {
if (selection.kind === 'Field' && !selection.name.value.startsWith('__')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure that this will not have unintended consequences? E.g. what if I name my custom field '__mrp'?

Is there an argument against checking for the full string '__typename'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GraphQL is using "__" in various places for internal field.

https://graphql.org/learn/introspection/
or
__resolveType

so I felt to future proof it in case there would be some additions to GraphQL spec in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you prefer just __typename - I will change it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had another thought - perhaps a way to avoid the entire issue with the naming convention is to just make the function ignore an undefined inputType on line 133, with const arg of inputType?.args ?? [].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const name = selection.name.value;
const inputType = mutationType.getFields()[name];
for (const arg of inputType.args) {
Expand Down