-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move fillLeafs to toolkit * move getSelectedOperationName to toolkit * move mergeAst to toolkit * remove unused utility module * demote version bump to patch
- Loading branch information
1 parent
8be164b
commit 84d8985
Showing
14 changed files
with
232 additions
and
237 deletions.
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,6 @@ | ||
--- | ||
'graphiql': patch | ||
'@graphiql/toolkit': minor | ||
--- | ||
|
||
Move the `fillLeafs` utility function from `graphiql` into `@graphiql/toolkit` and deprecate the export from `graphiql` |
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 @@ | ||
--- | ||
'graphiql': patch | ||
'@graphiql/toolkit': minor | ||
--- | ||
|
||
Move the `mergeAst` utility function from `graphiql` into `@graphiql/toolkit` and deprecate the export from `graphiql` |
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 @@ | ||
--- | ||
'graphiql': patch | ||
'@graphiql/toolkit': minor | ||
--- | ||
|
||
Move the `getSelectedOperationName` utility function from `graphiql` into `@graphiql/toolkit` and deprecate the export from `graphiql` |
164 changes: 164 additions & 0 deletions
164
packages/graphiql-toolkit/src/graphql-helpers/__tests__/merge-ast.spec.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,164 @@ | ||
import { | ||
GraphQLInt, | ||
GraphQLObjectType, | ||
GraphQLSchema, | ||
parse, | ||
print, | ||
} from 'graphql'; | ||
|
||
import { mergeAst } from '../merge-ast'; | ||
|
||
const schema = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'Test', | ||
fields: { | ||
id: { | ||
type: GraphQLInt, | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
describe('MergeAst', () => { | ||
it('does not modify query with no fragments', () => { | ||
const query = ` | ||
query Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
query Test { | ||
id | ||
}`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
expect(parseMergeAndPrint(query, schema)).toBe(mergedQuery); | ||
}); | ||
|
||
it('inlines simple nested fragment', () => { | ||
const query = ` | ||
query Test { | ||
...Fragment1 | ||
} | ||
fragment Fragment1 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
query Test { | ||
...on Test { | ||
id | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
query Test { | ||
id | ||
}`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); | ||
}); | ||
|
||
it('inlines triple nested fragment', () => { | ||
const query = ` | ||
query Test { | ||
...Fragment1 | ||
} | ||
fragment Fragment1 on Test { | ||
...Fragment2 | ||
} | ||
fragment Fragment2 on Test { | ||
...Fragment3 | ||
} | ||
fragment Fragment3 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
query Test { | ||
...on Test { | ||
...on Test { | ||
...on Test { | ||
id | ||
} | ||
} | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
query Test { | ||
id | ||
}`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); | ||
}); | ||
|
||
it('inlines multiple fragments', () => { | ||
const query = ` | ||
query Test { | ||
...Fragment1 | ||
...Fragment2 | ||
...Fragment3 | ||
} | ||
fragment Fragment1 on Test { | ||
id | ||
} | ||
fragment Fragment2 on Test { | ||
id | ||
} | ||
fragment Fragment3 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
query Test { | ||
...on Test { | ||
id | ||
} | ||
...on Test { | ||
id | ||
} | ||
...on Test { | ||
id | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
query Test { | ||
id | ||
}`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); | ||
}); | ||
|
||
it('removes duplicate fragment spreads', () => { | ||
const query = ` | ||
query Test { | ||
...Fragment1 | ||
...Fragment1 | ||
} | ||
fragment Fragment1 on Test { | ||
id | ||
}`; | ||
const mergedQuery = stripWhitespace(` | ||
query Test { | ||
...on Test { | ||
id | ||
} | ||
}`); | ||
const mergedQueryWithSchema = stripWhitespace(` | ||
query Test { | ||
id | ||
}`); | ||
expect(parseMergeAndPrint(query)).toBe(mergedQuery); | ||
expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema); | ||
}); | ||
}); | ||
|
||
function parseMergeAndPrint(query: string, maybeSchema?: GraphQLSchema) { | ||
return stripWhitespace(print(mergeAst(parse(query), maybeSchema))); | ||
} | ||
|
||
function stripWhitespace(str: string) { | ||
return str.replace(/\s/g, ''); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './auto-complete'; | ||
export * from './merge-ast'; | ||
export * from './operation-name'; |
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
9 changes: 1 addition & 8 deletions
9
...l/src/utility/getSelectedOperationName.ts → ...kit/src/graphql-helpers/operation-name.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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './async-helpers'; | ||
export * from './create-fetcher'; | ||
export * from './format'; | ||
export * from './graphql-helpers'; | ||
export * from './storage'; | ||
// TODO: move the most useful utilities from graphiql to here |
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.