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
I have a question about how to configure MockStore and addMocksToSchema to handle interface/union types.
For example, given the following schema:
typeQuery {
user(id: ID!): User
}
interfaceUser {
# In our case ID will always be unique across all implementing typesid: ID!name: String!
}
typeTeacherimplementsUser {
id: ID!name: String!classSize: Int!
}
typeStudentimplementsUser {
id: ID!name: String!grade: Int!
}
... if we want to set some specific data for a record that belongs to an interface/union we can do:
... but how do we get it back out in a resolver for the interface type User?
user: (_parent,{ id })=>{// Results in: Abstract type \"User\" was resolve to a non-object type \"User\"."// Not sure how to tell what type it should be?returnstore.get("User",id);}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a question about how to configure MockStore and addMocksToSchema to handle interface/union types.
For example, given the following schema:
... if we want to set some specific data for a record that belongs to an interface/union we can do:
... but how do we get it back out in a resolver for the interface type
User
?Here is a codesandbox with an example as well: https://codesandbox.io/s/friendly-wave-5or4h?file=/src/index.js
Is there any way to configure MockStore so that it understands the relationship between union/interface types and can help resolve the correct type?
Beta Was this translation helpful? Give feedback.
All reactions