Open nomin-sasabuchi opened 8 months ago
You’re definitely on the right track with the resolver. Mirage GraphQL tries to auto-resolve certain queries, but it’s pretty limited, and in your case the auto-resolution falls short.
It’s not obvious, but you’ll need to decorate the records from Mirage a bit to satisfy what GraphQL expects. For example, each object in the response needs to have a __typename
field.
You can import a function from Mirage GraphQL that will decorate the records accordingly:
import { adaptRecords } from '@miragejs/graphql/orm/records';
// ...
export default createServer({
routes() {
const resolvers = {
Mutation: {
updateSchedule(obj, args, context, info) {
// ...
return adaptRecords(context.mirageSchema.db.schedules.update(args.id, records));
}
}
};
// ...
},
});
Prerequisites
Operation has been confirmed for data acquisition, creation, and updating when there is no relationship
Problem
If you request an update for a schema that has the following relationships, the following error will occur. Why? If I exclude the related property (status: ScheduleState!), it works, so I think it's a problem with the relation. Do I need to write my own resolver in such a case?
Error: Cannot return null for non-nullable field Schedule.status.: {"response":{"errors":[{"message":"Cannot return null for non-nullable field Schedule.status.","locations":[{"line":11,"column":5}],"path":["updateSchedule","status"]}],"data":{"updateSchedule":null},
Code
Tried
By the way, I tried the following resolver, but it didn't work