-
Notifications
You must be signed in to change notification settings - Fork 463
Improve performance of client directive validation #1559
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc012e3
This commit seeks to improve the performance when determining
ebe1a71
fix TS error on failure to clean up removed function
91e5da4
Improve startup performance of CLI by removing extra validation
0a6820b
update changelog
bc638b2
Pragmatic take on improving codegen efficiency
11f869a
Add gitContext to checkPartialSchema mutation (#1560)
JakeDawkins 29d8f12
Clarify changelog and fix typo
JakeDawkins 3d45909
Merge branch 'jbaxleyiii/improve-client-performance' of github.com:ap…
JakeDawkins 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { fs } from "memfs"; | ||
|
|
||
| module.exports = fs; |
220 changes: 220 additions & 0 deletions
220
packages/apollo-language-server/src/errors/__tests__/NoMissingClientDirectives.test.ts
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,220 @@ | ||
| import { NoMissingClientDirectives } from "../validation"; | ||
| import { GraphQLClientProject } from "../../project/client"; | ||
| import { readFileSync } from "fs"; | ||
| import { basename } from "path"; | ||
|
|
||
| import { vol } from "memfs"; | ||
| import { LoadingHandler } from "../../loadingHandler"; | ||
| import { ApolloConfig, ClientConfig } from "../../config"; | ||
| import URI from "vscode-uri"; | ||
|
|
||
| const serviceSchema = /* GraphQL */ ` | ||
| type Query { | ||
| me: User | ||
| } | ||
|
|
||
| type User { | ||
| name: String | ||
| friends: [User] | ||
| } | ||
| `; | ||
| const clientSchema = /* GraphQL */ ` | ||
| extend type Query { | ||
| isOnline: Boolean | ||
| } | ||
| extend type User { | ||
| isLiked: Boolean | ||
| localUser: User | ||
| } | ||
| `; | ||
| const a = /* GraphQL */ ` | ||
| query a { | ||
| isOnline | ||
| me { | ||
| name | ||
| localUser @client { | ||
| friends { | ||
| isLiked | ||
| } | ||
| } | ||
| friends { | ||
| name | ||
| isLiked | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const b = /* GraphQL */ ` | ||
| query b { | ||
| me { | ||
| ... { | ||
| isLiked | ||
| } | ||
| ... @client { | ||
| localUser { | ||
| name | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const c = /* GraphQL */ ` | ||
| query c { | ||
| me { | ||
| ...isLiked | ||
| } | ||
| } | ||
| fragment localUser on User @client { | ||
| localUser { | ||
| name | ||
| } | ||
| } | ||
| fragment isLiked on User { | ||
| isLiked | ||
| ...localUser | ||
| } | ||
| `; | ||
|
|
||
| const d = /* GraphQL */ ` | ||
| fragment isLiked on User { | ||
| isLiked | ||
| } | ||
| query d { | ||
| me { | ||
| ...isLiked | ||
| ...locaUser | ||
| } | ||
| } | ||
| fragment localUser on User @client { | ||
| localUser { | ||
| name | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const e = /* GraphQL */ ` | ||
| fragment friends on User { | ||
| friends { | ||
| ...isLiked | ||
| ... on User @client { | ||
| localUser { | ||
| name | ||
| } | ||
| } | ||
| } | ||
| } | ||
| query e { | ||
| isOnline @client | ||
| me { | ||
| ...friends | ||
| } | ||
| } | ||
| fragment isLiked on User { | ||
| isLiked | ||
| } | ||
| `; | ||
|
|
||
| // TODO support inline fragment spreads | ||
| const f = /* GraphQL */ ` | ||
| query f { | ||
| me { | ||
| ...isLiked @client | ||
| } | ||
| } | ||
| fragment isLiked on User { | ||
| isLiked | ||
| } | ||
| `; | ||
|
|
||
| const rootURI = URI.file(process.cwd()); | ||
|
|
||
| const config = new ApolloConfig({ | ||
| client: { | ||
| service: { | ||
| name: "server", | ||
| localSchemaFile: "./schema.graphql" | ||
| }, | ||
| includes: ["./src/**.graphql"], | ||
| excludes: ["./__tests__"], | ||
| validationRules: [NoMissingClientDirectives] | ||
| }, | ||
| engine: {} | ||
| }) as ClientConfig; | ||
|
|
||
| class MockLoadingHandler implements LoadingHandler { | ||
| handle<T>(_message: string, value: Promise<T>): Promise<T> { | ||
| return value; | ||
| } | ||
| handleSync<T>(_message: string, value: () => T): T { | ||
| return value(); | ||
| } | ||
| showError(_message: string): void {} | ||
| } | ||
|
|
||
| jest.mock("fs"); | ||
|
|
||
| describe("client state", () => { | ||
| beforeEach(() => { | ||
| vol.fromJSON({ | ||
| "apollo.config.js": `module.exports = { | ||
| client: { | ||
| service: { | ||
| localSchemaFile: './schema.graphql' | ||
| } | ||
| } | ||
| }`, | ||
| "schema.graphql": serviceSchema, | ||
| "src/client-schema.graphql": clientSchema, | ||
| "src/a.graphql": a, | ||
| "src/b.graphql": b, | ||
| "src/c.graphql": c, | ||
| "src/d.graphql": d, | ||
| "src/e.graphql": e | ||
| // "src/f.graphql": f, | ||
| }); | ||
| }); | ||
| afterEach(jest.restoreAllMocks); | ||
|
|
||
| it("should report validation errors for missing @client directives", async () => { | ||
| const project = new GraphQLClientProject({ | ||
| config, | ||
| loadingHandler: new MockLoadingHandler(), | ||
| rootURI | ||
| }); | ||
|
|
||
| const errors = Object.create(null); | ||
| project.onDiagnostics(({ diagnostics, uri }) => { | ||
| const path = basename(URI.parse(uri).path); | ||
| diagnostics.forEach(({ error }: any) => { | ||
| if (!errors[path]) errors[path] = []; | ||
| errors[path].push(error); | ||
| }); | ||
| }); | ||
|
|
||
| await project.whenReady; | ||
| await project.validate(); | ||
|
|
||
| expect(errors).toMatchInlineSnapshot(` | ||
| Object { | ||
| "a.graphql": Array [ | ||
| [GraphQLError: @client directive is missing on local field "isOnline"], | ||
| [GraphQLError: @client directive is missing on local field "isLiked"], | ||
| ], | ||
| "b.graphql": Array [ | ||
| [GraphQLError: @client directive is missing on fragment around local fields "isLiked"], | ||
| ], | ||
| "c.graphql": Array [ | ||
| [GraphQLError: @client directive is missing on fragment "isLiked" around local fields "isLiked,localUser"], | ||
| ], | ||
| "d.graphql": Array [ | ||
| [GraphQLError: @client directive is missing on fragment "isLiked" around local fields "isLiked"], | ||
| ], | ||
| "e.graphql": Array [ | ||
| [GraphQLError: @client directive is missing on fragment "isLiked" around local fields "isLiked"], | ||
| ], | ||
| } | ||
| `); | ||
| }); | ||
| }); |
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.