Fragment cannot be spread here as objects of type "_Entity" can never be of type "X"
See original GitHub issueHi everyone! From apollo-server v 2.8.0 we are able to use same Value Types in multiple services: https://www.apollographql.com/docs/apollo-server/federation/core-concepts/#value-types
As an example I experimented with federation-demo: https://github.com/apollographql/federation-demo
I’ve added object type (Logs) in account service:
extend type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
name: String
username: String
logs: [Logs]
}
type Logs {
id: ID
message: String
}
and the same type in products service:
extend type Query {
topProducts(first: Int = 5): [Product]
}
type Product @key(fields: "upc") {
upc: String!
name: String
price: Int
weight: Int
logs: [Logs]
}
type Logs {
id: ID
message: String
}
all project is compiled successfully and now we may use one object type (Logs) in multiple services (according the rule of value types in federated service is that the types must be identical in name and contents):
But when i try to prepare data for logs property:
const users = [
{
id: "1",
name: "Ada Lovelace",
birthDate: "1815-12-10",
username: "@ada",
logs: [
{
id: 1,
message: "Some Message"
}
]
}
];
I got the following error:
"errors": [
{
"message": "400: Bad Request",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"response": {
"url": "http://localhost:4003/graphql",
"status": 400,
"statusText": "Bad Request",
"body": {
"errors": [
{
"message": "Fragment cannot be spread here as objects of type \"_Entity\" can never be of type \"Logs\".",
"locations": [
{
"line": 3,
"column": 5
}
],
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Fragment cannot be spread here as objects of type \"_Entity\" can never be of type \"Logs\".",
" at Object.InlineFragment (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\graphql\\validation\\rules\\PossibleFragmentSpreads.js:45:29)",
" at Object.enter (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\graphql\\language\\visitor.js:324:29)",
" at Object.enter (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\graphql\\language\\visitor.js:375:25)",
" at visit (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\graphql\\language\\visitor.js:242:26)",
" at Object.validate (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\graphql\\validation\\validate.js:54:22)",
" at validate (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:211:32)",
" at Object.<anonymous> (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:124:42)",
" at Generator.next (<anonymous>)",
" at fulfilled (C:\\_Redl\\temp\\federation-demo\\services\\products\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:4:58)",
" at processTicksAndRejections (internal/process/task_queues.js:85:5)"
]
}
}
}
]
}
}
}
}
],
Is it a bug or I’m doing something wrong?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
fragment cannot be spread here as objects of type "Query"
When I run the relay compiler I get the following error. Fragment "TaskList_tasks" cannot be spread here as objects of type "Query" can...
Read more >Fragment cannot be spread here as objects of type "X" can ...
Coding example for the question Fragment cannot be spread here as objects of type "X" can never be of type "Y"-Reactjs.
Read more >Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. ... Every fragment includes a subset...
Read more >Validation - GraphQL
Let's take a look at some invalid queries... A fragment cannot refer to itself or create a cycle, as this could result in...
Read more >GraphQL Content API - Contentful
The query complexity is 500. By default a Rich Text field has a total limit of 1000 linked entities of all supported types....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sgarciac the fix should be merged and released in 2 days or less. In simple cases, renaming the types locally per service can function as a workaround - and in the case of input types as you noted, this should certainly work.
Does anyone have a workaround for this issue while waiting for the bug fix? federating services that use the same value types is fairly common (for example, for pagination), so this is quite blocking D: