-
Notifications
You must be signed in to change notification settings - Fork 348
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
Allow to configure persisted operations plugin #6505
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c84e824
Add example and tests for persisted queries
EmrysMyrddin 9ba2147
add test for file documents
EmrysMyrddin 1871e6c
add tests to verify we can still run arbitrary queries
EmrysMyrddin 046f612
allow to configure persisted queries
EmrysMyrddin 4d73c7b
add documentation
EmrysMyrddin eaa1fc4
add persisted operation example to build list of integration test
EmrysMyrddin 51fce65
changeset
EmrysMyrddin bcfad0a
Fix changeset version
EmrysMyrddin 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 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,7 @@ | ||
--- | ||
"example-persisted-operations": minor | ||
"@graphql-mesh/config": minor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These packages are v0 so let's keep them bumping as patch, because minor means breaking for v0 |
||
"@graphql-mesh/types": minor | ||
EmrysMyrddin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
Allow to configure persisted operations behaviour |
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,26 @@ | ||
sources: | ||
- name: Hello World | ||
handler: | ||
jsonSchema: | ||
operations: | ||
- type: Query | ||
field: greeting | ||
method: GET | ||
path: / | ||
responseSample: | ||
hello: world | ||
plugins: | ||
- mock: | ||
mocks: | ||
- apply: Query.greeting | ||
documents: | ||
# Documents can be specified by filename or as a glob pattern | ||
- ./src/**/*.graphql | ||
# Or by inline definition | ||
- | | ||
query TypeName { | ||
__typename | ||
} | ||
|
||
persistedOperations: | ||
allowArbitraryOperations: true |
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 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
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,21 @@ | ||
{ | ||
"name": "example-persisted-operations", | ||
"version": "0.0.1", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"build": "mesh build", | ||
"start": "mesh dev", | ||
"test": "mesh build && jest" | ||
}, | ||
"dependencies": { | ||
"@graphql-mesh/cli": "0.88.5", | ||
"@graphql-mesh/json-schema": "0.97.4", | ||
"@graphql-mesh/plugin-mock": "0.96.3", | ||
"@graphql-yoga/plugin-sofa": "3.1.1", | ||
"graphql": "16.8.1" | ||
}, | ||
"devDependencies": { | ||
"jest": "29.7.0" | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"infiniteLoopProtection": true, | ||
"hardReloadOnChange": false, | ||
"template": "node", | ||
"container": { | ||
"node": "21" | ||
} | ||
} |
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 @@ | ||
query HelloWorld { | ||
greeting { | ||
hello | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
examples/persisted-operations/tests/persisted-queries.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,96 @@ | ||
import { join } from 'path'; | ||
import { ExecutionResult } from 'graphql'; | ||
import { findAndParseConfig } from '@graphql-mesh/cli'; | ||
import { createMeshHTTPHandler, MeshHTTPHandler } from '@graphql-mesh/http'; | ||
import { getMesh, MeshInstance } from '@graphql-mesh/runtime'; | ||
|
||
const baseDir = join(__dirname, '..'); | ||
|
||
const meshInstances = { | ||
'Mesh runtime': async () => { | ||
const config = await findAndParseConfig({ dir: baseDir }); | ||
return getMesh(config); | ||
}, | ||
'Mesh artifact': async () => { | ||
const { getBuiltMesh } = await import('../.mesh/index'); | ||
return getBuiltMesh(); | ||
}, | ||
}; | ||
|
||
describe('Persisted Queries', () => { | ||
describe.each(Object.entries(meshInstances))('%s', (_, getMeshInstance) => { | ||
let mesh: MeshInstance; | ||
let meshHttp: MeshHTTPHandler; | ||
|
||
beforeAll(async () => { | ||
mesh = await getMeshInstance(); | ||
meshHttp = createMeshHTTPHandler({ | ||
baseDir, | ||
getBuiltMesh: () => Promise.resolve(mesh), | ||
}); | ||
}); | ||
|
||
afterAll(() => mesh.destroy()); | ||
|
||
it('should give correct response for inline persisted operation', async () => { | ||
const response = await meshHttp.fetch('/graphql', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
extensions: { | ||
persistedQuery: { | ||
version: 1, | ||
sha256Hash: 'ece829f774dcb3e1358987feb1f86832b39472406a3ef65dce6a2a740304148a', | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
const result = (await response.json()) as ExecutionResult; | ||
expect(result?.errors).toBeFalsy(); | ||
expect(result.data).toEqual({ __typename: 'Query' }); | ||
}); | ||
|
||
it('should give correct response for file documents', async () => { | ||
const response = await meshHttp.fetch('/graphql', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
extensions: { | ||
persistedQuery: { | ||
version: 1, | ||
sha256Hash: '2e0534aab6b2b83bc791439094830b45b621deec2087b8567539f37defd391ac', | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
const result = (await response.json()) as ExecutionResult; | ||
expect(result?.errors).toBeFalsy(); | ||
expect(result.data).toEqual({ greeting: { hello: 'world' } }); | ||
}); | ||
|
||
it('should not restrict to persisted queries only', async () => { | ||
const response = await meshHttp.fetch('/graphql', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
query: /* GraphQL */ ` | ||
query HelloWorld { | ||
greeting { | ||
__typename | ||
} | ||
} | ||
`, | ||
}), | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
const result = (await response.json()) as ExecutionResult; | ||
expect(result?.errors).toBeFalsy(); | ||
expect(result.data).toEqual({ greeting: { __typename: 'query_greeting' } }); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
"packageManager": "[email protected]", | ||
"scripts": { | ||
"build": "bob build", | ||
"build-test-artifacts": "yarn workspace json-schema-example build && yarn workspace example-fastify build", | ||
"build-test-artifacts": "yarn workspace json-schema-example build && yarn workspace example-fastify build && yarn workspace example-persisted-operations build", | ||
"build:website": "cd website && yarn build", | ||
"ci:lint": "eslint --output-file eslint_report.json --ext .ts --format json \"./packages/**/src/**/*.ts\"", | ||
"clean": "rm -rf packages/**/dist packages/**/**/dist examples/**/node_modules/.bin/*mesh* .bob", | ||
|
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to bump the examples version