Skip to content

Fix check keys usage #46

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/helpers/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function checkKeySanity(servicesSchemaMap, service: Service): Change[] {
type KeyDirective = {
fields: string;
serviceName: string;
isResolvable;
};

type TypeKeyMap = Map<string, KeyDirective[]>;
Expand Down Expand Up @@ -132,6 +133,15 @@ function extractKeysFromSDL(
? fieldsArg.value.value
: '';

const resolvableKeyPresent = key.arguments?.find(
(arg) => arg.name.value === 'resolvable'
);
const isResolvable = resolvableKeyPresent
? resolvableKeyPresent.value.kind === 'BooleanValue'
? resolvableKeyPresent.value.value
: true
: true;

const normalizedFieldsValue = normalizeKeyFields(fieldsValue);

if (!keyMap.has(node.name.value)) {
Expand All @@ -141,6 +151,7 @@ function extractKeysFromSDL(
keyMap.get(node.name.value)?.push({
fields: normalizedFieldsValue,
serviceName,
isResolvable,
});
}
},
Expand Down Expand Up @@ -191,6 +202,7 @@ function checkServiceKeysWithinSupergraph(
const supergraphTypeKeys = supergraphKeys.get(typeName);
for (const key of keys) {
if (
!key.isResolvable &&
supergraphTypeKeys &&
!supergraphTypeKeys.some((k) => k.fields === key.fields)
) {
Expand Down
49 changes: 48 additions & 1 deletion test/integration/5_diff.feature
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Feature: As a customer
{
"name": "Reviews",
"version": "newest",
"type_defs": "type User @key(fields: \"email\") { email: String! reviews: [Review] } type Review { id: ID! body: String }"
"type_defs": "type User @key(fields: \"email\", resolvable: false) { email: String! reviews: [Review] } type Review { id: ID! body: String }"
}
"""
Then the response status code should be 200
Expand All @@ -268,3 +268,50 @@ Feature: As a customer
}
"""

Scenario: Checking keys with different schemas (owner graph)
Given the database is imported from 'breakdown_schema_db'
And I send a "POST" request to "/schema/push" with body:
"""
{
"name": "User",
"version": "newest",
"type_defs": "type Query { getUser: User } type User @key(fields: \"id\") { id: ID! name: String }"
}
"""
And I send a "POST" request to "/schema/push" with body:
"""
{
"name": "Email",
"version": "newest",
"type_defs": "type Query { getEmails: User } type User @key(fields: \"id\", resolvable: false) { id: ID! name: String }"
}
"""
Then I send a "POST" request to "/schema/diff" with body:
"""
{
"name": "User",
"version": "newest",
"type_defs": "type Query { getUser: User } type User @key(fields: \"id\") @key(fields: \"email\") { id: ID! name: String, email: String! }"
}
"""
Then the response status code should be 200
And the response should be in JSON and contain:
"""
{
"success": true,
"data": [{
"criticality": {
"level": "NON_BREAKING"
},
"message": "Field 'email' was added to object type 'User'",
"meta": {
"addedFieldName": "email",
"typeName": "User",
"typeType": "object type"
},
"path": "User.email",
"type": "FIELD_ADDED"
}]
}
"""

Loading