-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also validate against improper @inaccessible usage
- Loading branch information
1 parent
884da2c
commit 3d51e58
Showing
5 changed files
with
201 additions
and
97 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
173 changes: 173 additions & 0 deletions
173
...c/composition/validate/preComposition/__tests__/tagOrInaccessibleUsedWithExternal.test.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,173 @@ | ||
import { tagOrInaccessibleUsedWithExternal } from '..'; | ||
import { | ||
gql, | ||
graphqlErrorSerializer, | ||
} from 'apollo-federation-integration-testsuite'; | ||
|
||
expect.addSnapshotSerializer(graphqlErrorSerializer); | ||
|
||
describe('tagOrInaccessibleUsedWithExternal', () => { | ||
describe('no errors', () => { | ||
it('has no errors @external and @tag are used separately', () => { | ||
const serviceA = { | ||
typeDefs: gql` | ||
type Query { | ||
product: Product @tag(name: "prod") | ||
} | ||
extend type Product @key(fields: "sku") { | ||
sku: String @external | ||
} | ||
`, | ||
name: 'serviceA', | ||
}; | ||
|
||
const errors = tagOrInaccessibleUsedWithExternal(serviceA); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
|
||
it('has no errors @external and @inaccessible are used separately', () => { | ||
const serviceA = { | ||
typeDefs: gql` | ||
type Query { | ||
product: Product @inaccessible | ||
} | ||
extend type Product @key(fields: "sku") { | ||
sku: String @external | ||
} | ||
`, | ||
name: 'serviceA', | ||
}; | ||
|
||
const errors = tagOrInaccessibleUsedWithExternal(serviceA); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
describe('errors', () => { | ||
it('errors when `@external` and `@tag` are used on the same field of an object extension', () => { | ||
const serviceA = { | ||
typeDefs: gql` | ||
type Query { | ||
product: Product @tag(name: "prod") | ||
} | ||
extend type Product @key(fields: "sku") { | ||
sku: String @external @tag(name: "prod") | ||
} | ||
`, | ||
name: 'serviceA', | ||
}; | ||
|
||
const errors = tagOrInaccessibleUsedWithExternal(serviceA); | ||
expect(errors).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"code": "TAG_USED_WITH_EXTERNAL", | ||
"locations": Array [ | ||
Object { | ||
"column": 25, | ||
"line": 7, | ||
}, | ||
], | ||
"message": "[serviceA] Product.sku -> Found illegal use of @tag directive. @tag directives cannot currently be used in tandem with an @external directive.", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('errors when `@external` and `@tag` are used on the same field of an interface extension', () => { | ||
const serviceA = { | ||
typeDefs: gql` | ||
type Query { | ||
product: Product @tag(name: "prod") | ||
} | ||
extend interface Product @key(fields: "sku") { | ||
sku: String @external @tag(name: "prod") | ||
} | ||
`, | ||
name: 'serviceA', | ||
}; | ||
|
||
const errors = tagOrInaccessibleUsedWithExternal(serviceA); | ||
expect(errors).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"code": "TAG_USED_WITH_EXTERNAL", | ||
"locations": Array [ | ||
Object { | ||
"column": 25, | ||
"line": 7, | ||
}, | ||
], | ||
"message": "[serviceA] Product.sku -> Found illegal use of @tag directive. @tag directives cannot currently be used in tandem with an @external directive.", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('errors when `@external` and `@inaccessible` are used on the same field of an object extension', () => { | ||
const serviceA = { | ||
typeDefs: gql` | ||
type Query { | ||
product: Product @tag(name: "prod") | ||
} | ||
extend type Product @key(fields: "sku") { | ||
sku: String @external @inaccessible | ||
} | ||
`, | ||
name: 'serviceA', | ||
}; | ||
|
||
const errors = tagOrInaccessibleUsedWithExternal(serviceA); | ||
expect(errors).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"code": "INACCESSIBLE_USED_WITH_EXTERNAL", | ||
"locations": Array [ | ||
Object { | ||
"column": 25, | ||
"line": 7, | ||
}, | ||
], | ||
"message": "[serviceA] Product.sku -> Found illegal use of @inaccessible directive. @inaccessible directives cannot currently be used in tandem with an @external directive.", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('errors when `@external` and `@inaccessible` are used on the same field of an interface extension', () => { | ||
const serviceA = { | ||
typeDefs: gql` | ||
type Query { | ||
product: Product @tag(name: "prod") | ||
} | ||
extend interface Product @key(fields: "sku") { | ||
sku: String @external @inaccessible | ||
} | ||
`, | ||
name: 'serviceA', | ||
}; | ||
|
||
const errors = tagOrInaccessibleUsedWithExternal(serviceA); | ||
expect(errors).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"code": "INACCESSIBLE_USED_WITH_EXTERNAL", | ||
"locations": Array [ | ||
Object { | ||
"column": 25, | ||
"line": 7, | ||
}, | ||
], | ||
"message": "[serviceA] Product.sku -> Found illegal use of @inaccessible directive. @inaccessible directives cannot currently be used in tandem with an @external directive.", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
}); |
89 changes: 0 additions & 89 deletions
89
federation-js/src/composition/validate/preComposition/__tests__/tagUsedWithExternal.test.ts
This file was deleted.
Oops, something went wrong.
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