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

(graphcache) - add special case for fetching an introspection result in graphcache #893

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/afraid-dragons-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/exchange-graphcache': patch
---

Add special-case for fetching an introspection result in our schema-checking, this avoids an error when urql-devtools fetches the backend graphql schema.
2 changes: 2 additions & 0 deletions exchanges/graphcache/src/ast/schemaPredicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const isFieldNullable = (
typename: string,
fieldName: string
): boolean => {
if (fieldName === '__schema') return true;
const field = getField(schema, typename, fieldName);
return !!field && isNullableType(field.type);
};
Expand All @@ -42,6 +43,7 @@ export const isFieldAvailableOnType = (
typename: string,
fieldName: string
): boolean => {
if (fieldName === '__schema') return true;
return !!getField(schema, typename, fieldName);
};

Expand Down
13 changes: 11 additions & 2 deletions exchanges/graphcache/src/store/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { write, writeOptimistic } from '../operations/write';
import * as InMemoryData from './data';
import { Store } from './store';
import { noop } from '../test-utils/utils';
import { getIntrospectionQuery, parse } from 'graphql';

const Appointment = gql`
query appointment($id: String) {
Expand Down Expand Up @@ -385,10 +386,9 @@ describe('Store with OptimisticMutationConfig', () => {
{
query: connection,
},
// @ts-ignore
{
exercisesConnection: null,
}
} as any
);
let { data } = query(store, { query: connection });

Expand Down Expand Up @@ -803,4 +803,13 @@ describe('Store with storage', () => {
);
expect(warnMessage).toContain('https://bit.ly/2XbVrpR#24');
});

it('should not warn for an introspection result root', function () {
// eslint-disable-next-line
const schema = require('../test-utils/simple_schema.json');
const store = new Store({ schema });

query(store, { query: parse(getIntrospectionQuery()) }, schema);
expect(console.warn).toBeCalledTimes(0);
});
});