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
// server.js
const server = new ApolloServer({
...
mockEntireSchema: false,
});
// schema.gql
type User {
id: ObjectId
username: String
nickname: String
}
// mocks.js
export default {
User(){
nickname: 'John'
}
String: ()=>'Bob'
}
// resolvers.js
export default {
Query: {
// Both of query get Object type User with `undefined` value on `nickname` prop
// `user resolver` is working correctly. it return user with nickname `John`
user:(root, {id}, { db })=>db.get('user').find({ id }).value()
// `users resolver` is wrong. it return user with nickname `Bob`
users:(root, args, { db })=>db.get('user').value()
}
I found that we can fix this by edit this function:
This mean it will return list value from resolver and ignore list value from mock resolver which is wrong.
We need to merge value from resolver and mock server together and it done.
I add this code above that line and it work!.
I found that we can fix this by edit this function:
graphql-tools/packages/mock/src/addMocksToSchema.ts
Lines 180 to 206 in b8308ef
In case of return type
List
, it will go to this line.graphql-tools/packages/mock/src/addMocksToSchema.ts
Line 205 in b8308ef
This mean it will return list value from resolver and ignore list value from mock resolver which is wrong.
We need to merge value from resolver and mock server together and it done.
I add this code above that line and it work!.
I'm not quite sure. this is the right approach or not.
Hope it help. 😄
The text was updated successfully, but these errors were encountered: