forked from dotansimha/graphql-yoga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APQ: Follow Apollo's implementation more & integration tests for Apol…
…lo Client (dotansimha#2985) * Integration tests for APQ plugin and Apollo Client * Skip v15 * Go * Go * Lint * Follow Apollo's implementation * Fix tests * chore(dependencies): updated changesets for modified dependencies --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
968eb01
commit 75ee852
Showing
8 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-yoga_plugin-prometheus-2985-dependencies.md
This file contains 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,6 @@ | ||
--- | ||
'@graphql-yoga/plugin-prometheus': patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@envelop/[email protected]` | ||
↗︎](https://www.npmjs.com/package/@envelop/prometheus/v/8.0.1) (from `8.0.0`, in `dependencies`) |
This file contains 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,5 @@ | ||
--- | ||
'@graphql-yoga/plugin-apq': patch | ||
--- | ||
|
||
Add `extensions.code` to match Apollo's APQ implementation |
This file contains 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
91 changes: 91 additions & 0 deletions
91
packages/plugins/apq/__integration-tests__/apollo-client.test.ts
This file contains 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,91 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import crypto from 'node:crypto'; | ||
import { parse, version } from 'graphql'; | ||
import { createSchema, createYoga } from 'graphql-yoga'; | ||
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'; | ||
import { createPersistedQueryLink } from '@apollo/client/link/persisted-queries'; | ||
import { useAPQ } from '@graphql-yoga/plugin-apq'; | ||
|
||
function sha256(input: string) { | ||
return crypto.createHash('sha256').update(input).digest('hex'); | ||
} | ||
|
||
describe('Automatic Persisted Queries', () => { | ||
if (version.startsWith('15')) { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
it('noop', () => {}); | ||
return; | ||
} | ||
const server = createYoga({ | ||
schema: createSchema({ | ||
typeDefs: /* GraphQL */ ` | ||
type Query { | ||
foo: String | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
foo() { | ||
return 'bar'; | ||
}, | ||
}, | ||
}, | ||
}), | ||
plugins: [useAPQ()], | ||
}); | ||
|
||
const fetchSpy = jest.fn(async (info: RequestInfo | URL, init: RequestInit) => | ||
server.fetch(info as URL, init), | ||
); | ||
|
||
const linkChain = createPersistedQueryLink({ sha256 }).concat( | ||
new HttpLink({ uri: 'http://localhost:4000/graphql', fetch: fetchSpy }), | ||
); | ||
|
||
const client = new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
link: linkChain, | ||
}); | ||
|
||
it('works', async () => { | ||
const query = '{\n foo\n}'; | ||
const { data } = await client.query({ query: parse(query) }); | ||
|
||
expect(data).toEqual({ foo: 'bar' }); | ||
|
||
expect(fetchSpy).toHaveBeenCalledTimes(2); | ||
expect(fetchSpy.mock.calls[0][1]).toMatchObject({ | ||
body: JSON.stringify({ | ||
variables: {}, | ||
extensions: { | ||
persistedQuery: { | ||
version: 1, | ||
sha256Hash: sha256(query), | ||
}, | ||
}, | ||
}), | ||
headers: { | ||
'content-type': 'application/json', | ||
accept: '*/*', | ||
}, | ||
method: 'POST', | ||
}); | ||
expect(fetchSpy.mock.calls[1][1]).toMatchObject({ | ||
body: JSON.stringify({ | ||
variables: {}, | ||
extensions: { | ||
persistedQuery: { | ||
version: 1, | ||
sha256Hash: sha256(query), | ||
}, | ||
}, | ||
query, | ||
}), | ||
headers: { | ||
'content-type': 'application/json', | ||
accept: '*/*', | ||
}, | ||
method: 'POST', | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.