Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge list fields correctly * Changesets * Tests
- Loading branch information
Showing
8 changed files
with
158 additions
and
4 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,5 @@ | ||
--- | ||
"@graphql-tools/federation": patch | ||
--- | ||
|
||
Show responses in debug logging with `DEBUG` env var |
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-tools/delegate": patch | ||
--- | ||
|
||
Merge list fields correctly |
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-tools/stitch": patch | ||
--- | ||
|
||
Exclude fields with `__typename` while extracting missing fields for the type merging |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ignored-hidden |
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,112 @@ | ||
import { getOperationAST, isObjectType, Kind, parse, print, SelectionSetNode } from 'graphql'; | ||
import { makeExecutableSchema } from '@graphql-tools/schema'; | ||
import { stripWhitespaces } from '../../merge/tests/utils'; | ||
import { extractUnavailableFields } from '../src/getFieldsNotInSubschema'; | ||
|
||
describe('extractUnavailableFields', () => { | ||
it('should extract correct fields', () => { | ||
const schema = makeExecutableSchema({ | ||
typeDefs: /* GraphQL */ ` | ||
type Query { | ||
user: User | ||
} | ||
type User { | ||
id: ID! | ||
name: String! | ||
} | ||
`, | ||
}); | ||
const userQuery = /* GraphQL */ ` | ||
query { | ||
user { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`; | ||
const userQueryDoc = parse(userQuery, { noLocation: true }); | ||
const operationAst = getOperationAST(userQueryDoc, null); | ||
if (!operationAst) { | ||
throw new Error('Operation AST not found'); | ||
} | ||
const selectionSet = operationAst.selectionSet; | ||
const userSelection = selectionSet.selections[0]; | ||
if (userSelection.kind !== 'Field') { | ||
throw new Error('User selection not found'); | ||
} | ||
const queryType = schema.getType('Query'); | ||
if (!isObjectType(queryType)) { | ||
throw new Error('Query type not found'); | ||
} | ||
const userField = queryType.getFields()['user']; | ||
if (!userField) { | ||
throw new Error('User field not found'); | ||
} | ||
const unavailableFields = extractUnavailableFields(userField, userSelection); | ||
const extractedSelectionSet: SelectionSetNode = { | ||
kind: Kind.SELECTION_SET, | ||
selections: unavailableFields, | ||
}; | ||
expect(stripWhitespaces(print(extractedSelectionSet))).toBe( | ||
`{ email friends { id name email } }`, | ||
); | ||
}); | ||
it('excludes the fields only with __typename', () => { | ||
const schema = makeExecutableSchema({ | ||
typeDefs: /* GraphQL */ ` | ||
type Query { | ||
user: User | ||
} | ||
type User { | ||
id: ID! | ||
name: String! | ||
friends: [User] | ||
} | ||
`, | ||
}); | ||
const userQuery = /* GraphQL */ ` | ||
query { | ||
user { | ||
__typename | ||
id | ||
name | ||
friends { | ||
__typename | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`; | ||
const userQueryDoc = parse(userQuery, { noLocation: true }); | ||
const operationAst = getOperationAST(userQueryDoc, null); | ||
if (!operationAst) { | ||
throw new Error('Operation AST not found'); | ||
} | ||
const selectionSet = operationAst.selectionSet; | ||
const userSelection = selectionSet.selections[0]; | ||
if (userSelection.kind !== 'Field') { | ||
throw new Error('User selection not found'); | ||
} | ||
const queryType = schema.getType('Query'); | ||
if (!isObjectType(queryType)) { | ||
throw new Error('Query type not found'); | ||
} | ||
const userField = queryType.getFields()['user']; | ||
if (!userField) { | ||
throw new Error('User field not found'); | ||
} | ||
const unavailableFields = extractUnavailableFields(userField, userSelection); | ||
const extractedSelectionSet: SelectionSetNode = { | ||
kind: Kind.SELECTION_SET, | ||
selections: unavailableFields, | ||
}; | ||
expect(stripWhitespaces(print(extractedSelectionSet))).toBe(''); | ||
}); | ||
}); |