-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix: Upgrade graphql and@apollo/client
#11200
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
Open
erwanMarmelab
wants to merge
9
commits into
next
Choose a base branch
from
upgrade-graphql-and-apollo/client
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5712a4e
feat: Upgrade `graphql` and`@apollo/client`
erwanMarmelab 29324b2
Add some imports in packages + revert some type updates
erwanMarmelab f9864b6
fix build
erwanMarmelab af72ab6
Fix clientOptions uri + credentials + headers with Apollo Client 4
erwanMarmelab a9dbb86
Fix error handling and query result types with Apollo Client 4
erwanMarmelab dd6fdf3
Fix graphql + rxjs peer dependencies + buildGqlQuery
erwanMarmelab 57bfd02
fix build
erwanMarmelab 42108d4
fix demo build
erwanMarmelab 75258f8
fix graphQl demo
erwanMarmelab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,24 @@ | ||
| import { | ||
| IntrospectionListTypeRef, | ||
| IntrospectionType, | ||
| IntrospectionTypeRef, | ||
| TypeKind, | ||
| TypeNode, | ||
| } from 'graphql'; | ||
| import * as gqlTypes from 'graphql-ast-types-browser'; | ||
|
|
||
| const isWrappingTypeRef = ( | ||
| type: IntrospectionType | IntrospectionTypeRef | ||
| ): type is Extract<IntrospectionTypeRef, { ofType: unknown }> => | ||
| type.kind === TypeKind.LIST || type.kind === TypeKind.NON_NULL; | ||
|
|
||
| export const getGqlType = ( | ||
| type: IntrospectionType | IntrospectionListTypeRef | IntrospectionTypeRef | ||
| type: IntrospectionType | IntrospectionTypeRef | ||
| ): TypeNode => { | ||
| switch (type.kind) { | ||
| case TypeKind.LIST: | ||
| return gqlTypes.listType(getGqlType(type.ofType)); | ||
|
|
||
| case TypeKind.NON_NULL: | ||
| return gqlTypes.nonNullType(getGqlType(type.ofType)); | ||
|
|
||
| default: | ||
| return gqlTypes.namedType(gqlTypes.name(type.name)); | ||
| if (isWrappingTypeRef(type)) { | ||
| return type.kind === TypeKind.LIST | ||
| ? gqlTypes.listType(getGqlType(type.ofType)) | ||
| : gqlTypes.nonNullType(getGqlType(type.ofType)); | ||
| } | ||
|
|
||
| return gqlTypes.namedType(gqlTypes.name(type.name)); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { HttpLink } from '@apollo/client'; | ||
| import gql from 'graphql-tag'; | ||
|
|
||
| import buildApolloClient from './buildApolloClient'; | ||
|
|
||
| const okResponse = () => | ||
| Promise.resolve( | ||
| new Response(JSON.stringify({ data: { foo: 'bar' } }), { | ||
| status: 200, | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
| ); | ||
|
|
||
| describe('buildApolloClient', () => { | ||
| let fetchSpy; | ||
|
|
||
| beforeEach(() => { | ||
| fetchSpy = jest | ||
| .spyOn(globalThis, 'fetch') | ||
| .mockImplementation(okResponse as any); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fetchSpy.mockRestore(); | ||
| }); | ||
|
|
||
| const runQuery = async client => { | ||
| await client.query({ | ||
| query: gql` | ||
| query { | ||
| foo | ||
| } | ||
| `, | ||
| fetchPolicy: 'no-cache', | ||
| }); | ||
| return fetchSpy.mock.calls[0]; | ||
| }; | ||
|
|
||
| it('sends the query to the uri passed in options', async () => { | ||
| const client = buildApolloClient({ | ||
| uri: 'http://example.com/graphql', | ||
| }); | ||
|
|
||
| const [url] = await runQuery(client); | ||
|
|
||
| expect(String(url)).toBe('http://example.com/graphql'); | ||
| }); | ||
|
|
||
| it('forwards credentials and headers to the HttpLink', async () => { | ||
| const client = buildApolloClient({ | ||
| uri: 'http://example.com/graphql', | ||
| credentials: 'include', | ||
| headers: { 'X-Custom': 'yes' }, | ||
| }); | ||
|
|
||
| const [, init] = await runQuery(client); | ||
|
|
||
| expect(init.credentials).toBe('include'); | ||
| expect(new Headers(init.headers).get('X-Custom')).toBe('yes'); | ||
| }); | ||
|
|
||
| it('lets an explicit link take precedence over uri', async () => { | ||
| const client = buildApolloClient({ | ||
| uri: 'http://ignored.example.com/graphql', | ||
| link: new HttpLink({ uri: 'http://explicit.example.com/graphql' }), | ||
| }); | ||
|
|
||
| const [url] = await runQuery(client); | ||
|
|
||
| expect(String(url)).toBe('http://explicit.example.com/graphql'); | ||
| }); | ||
|
|
||
| it('builds a client without any options', () => { | ||
| expect(buildApolloClient().link).toBeDefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.