This repository was archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Online schema support #215
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
798596e
Online schema support
lostplan 6658b6b
Support `.graphqlconfig` without `schemaPath`
lostplan 249e78e
Update tests
lostplan 8766711
Update cache key logic
lostplan b06331b
Fix validation
lostplan 9219270
some review tweaks
lostplan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ import {expect} from 'chai'; | |
import {GraphQLSchema} from 'graphql/type'; | ||
import {parse} from 'graphql/language'; | ||
import {getGraphQLConfig} from 'graphql-config'; | ||
import {beforeEach, describe, it} from 'mocha'; | ||
import {beforeEach, afterEach, describe, it} from 'mocha'; | ||
import fetchMock from 'fetch-mock'; | ||
|
||
import {GraphQLCache} from '../GraphQLCache'; | ||
import {getQueryAndRange} from '../MessageProcessor'; | ||
|
@@ -25,20 +26,56 @@ function wihtoutASTNode(definition: object) { | |
|
||
describe('GraphQLCache', () => { | ||
let cache; | ||
let graphQLRC; | ||
|
||
beforeEach(async () => { | ||
const configDir = __dirname; | ||
const graphQLRC = getGraphQLConfig(configDir); | ||
graphQLRC = getGraphQLConfig(configDir); | ||
cache = new GraphQLCache(configDir, graphQLRC); | ||
}); | ||
|
||
afterEach(() => { | ||
fetchMock.restore(); | ||
}); | ||
|
||
describe('getSchema', () => { | ||
it('generates the schema correctly for the test app config', async () => { | ||
const schema = await cache.getSchema('testWithSchema'); | ||
expect(schema instanceof GraphQLSchema).to.equal(true); | ||
}); | ||
|
||
it('does not generate a schema without a schema path', async () => { | ||
it('generates the schema correctly from endpoint', async () => { | ||
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. good stuff here 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. :) |
||
const introspectionResult = await graphQLRC | ||
.getProjectConfig('testWithSchema') | ||
.resolveIntrospection(); | ||
|
||
fetchMock.mock({ | ||
matcher: '*', | ||
response: { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: introspectionResult, | ||
}, | ||
}); | ||
|
||
const schema = await cache.getSchema('testWithEndpoint'); | ||
expect(fetchMock.called('*')).to.equal(true); | ||
expect(schema instanceof GraphQLSchema).to.equal(true); | ||
}); | ||
|
||
it('falls through to schema on disk if endpoint fails', async () => { | ||
fetchMock.mock({ | ||
matcher: '*', | ||
response: 500, | ||
}); | ||
|
||
const schema = await cache.getSchema('testWithEndpointAndSchema'); | ||
expect(fetchMock.called('*')).to.equal(true); | ||
expect(schema instanceof GraphQLSchema).to.equal(true); | ||
}); | ||
|
||
it('does not generate a schema without a schema path or endpoint', async () => { | ||
const schema = await cache.getSchema('testWithoutSchema'); | ||
expect(schema instanceof GraphQLSchema).to.equal(false); | ||
}); | ||
|
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 |
---|---|---|
|
@@ -1413,6 +1413,13 @@ fb-watchman@^2.0.0: | |
dependencies: | ||
bser "^2.0.0" | ||
|
||
fetch-mock@^6.0.0: | ||
version "6.0.0" | ||
resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-6.0.0.tgz#4edb5acefa8ea90d7eb4213130ab73137fac9df1" | ||
dependencies: | ||
glob-to-regexp "^0.3.0" | ||
path-to-regexp "^2.1.0" | ||
|
||
figures@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962" | ||
|
@@ -1635,6 +1642,10 @@ glob-parent@^3.1.0: | |
is-glob "^3.1.0" | ||
path-dirname "^1.0.0" | ||
|
||
glob-to-regexp@^0.3.0: | ||
version "0.3.0" | ||
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" | ||
|
||
[email protected], glob@^7.0.3, glob@^7.0.5, glob@^7.1.2: | ||
version "7.1.2" | ||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" | ||
|
@@ -1703,6 +1714,16 @@ graphql-import@^0.1.7: | |
graphql "^0.12.3" | ||
lodash "^4.17.4" | ||
|
||
graphql-language-service-parser@^0.1.0-0: | ||
version "0.1.14" | ||
resolved "https://registry.yarnpkg.com/graphql-language-service-parser/-/graphql-language-service-parser-0.1.14.tgz#dd25abda5dcff4f2268c9a19e026004271491661" | ||
dependencies: | ||
graphql-language-service-types "^0.1.14" | ||
|
||
graphql-language-service-types@^0.1.0-0, graphql-language-service-types@^0.1.14: | ||
version "0.1.14" | ||
resolved "https://registry.yarnpkg.com/graphql-language-service-types/-/graphql-language-service-types-0.1.14.tgz#e6112785fc23ea8222f59a7f00e61b359f263c88" | ||
|
||
graphql-request@^1.4.0: | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-1.4.0.tgz#f5b067c83070296d93fb45760e83dfad0d9f537a" | ||
|
@@ -2600,6 +2621,10 @@ path-parse@^1.0.5: | |
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" | ||
|
||
path-to-regexp@^2.1.0: | ||
version "2.1.0" | ||
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.1.0.tgz#7e30f9f5b134bd6a28ffc2e3ef1e47075ac5259b" | ||
|
||
path-type@^1.0.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" | ||
|
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.
nit:
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.
Oh, it looks like
_getDefaultEndpoint
can return something that is falsy so destructuring here could possibly throw an error which is why I think it's handled below.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.
yup