You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
buildSubgraphSchema does not provide a __resolveType resolver for _Entity. @graphql-tools/mock provides a function addMocksToSchema that copies an existing schema into a new GraphQLSchema with mocked resolvers. There is a preserveResolvers config option that is meant to keep any existing resolvers, but the preserved elements may still be copied into a new schema object; specifically, unions that don't have resolveType defined.
Since buildSubgraphSchema does not provide a __resolveType for Entity, a new GraphQLUnionType is used based on the toConfig() results and the resolveType - this is just standard graphql-js and the _Entity union should copy over. You can view the relevant code in @graphql-tools/mockhere.
Related Issues and PRs
I believe this is also the root of #411 and #348. Another PR addresses the other issue of __resolveReference resolvers being dropped in a similar process with toConfig; that PR is needed for mocks to work and call the appropriate entities __resolveRefernce
Will give the following error (you can run the above query in sandbox:
{
errors: [
[GraphQLError: Abstract type "_Entity" must resolve to an Object type at runtime forfield "Query._entities". Either the "_Entity" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.] {
locations: [Array],
path: [Array],
extensions: [Object]
}
]
}
Workaround
You can provide the _Entity.__resolveType resolver to addMocksToSchema as shown below and in this codesandbox reproduction:
The error will be gone, unfortunately you won't get any data back because of the issue around __resolveRefernce, but this is fixed in this PR and should release in the future 🎉
(I couldn't figure out how to install the tarbill in code sandbox, but it worked locally in my identical sample to codesandbox)
The text was updated successfully, but these errors were encountered:
Bug Description
buildSubgraphSchema
does not provide a__resolveType
resolver for_Entity
.@graphql-tools/mock
provides a functionaddMocksToSchema
that copies an existing schema into a newGraphQLSchema
with mocked resolvers. There is apreserveResolvers
config option that is meant to keep any existing resolvers, but the preserved elements may still be copied into a new schema object; specifically, unions that don't haveresolveType
defined.Since
buildSubgraphSchema
does not provide a__resolveType
forEntity
, a newGraphQLUnionType
is used based on thetoConfig()
results and theresolveType
- this is just standardgraphql-js
and the_Entity
union should copy over. You can view the relevant code in@graphql-tools/mock
here.Related Issues and PRs
I believe this is also the root of #411 and #348. Another PR addresses the other issue of
__resolveReference
resolvers being dropped in a similar process withtoConfig
; that PR is needed for mocks to work and call the appropriate entities__resolveRefernce
Reproduction
Codesandbox example, example query:
Will give the following error (you can run the above query in sandbox:
Workaround
You can provide the
_Entity.__resolveType
resolver toaddMocksToSchema
as shown below and in this codesandbox reproduction:The error will be gone, unfortunately you won't get any data back because of the issue around __resolveRefernce, but this is fixed in this PR and should release in the future 🎉
(I couldn't figure out how to install the tarbill in code sandbox, but it worked locally in my identical sample to codesandbox)
The text was updated successfully, but these errors were encountered: