Hello guys!
I have question about typegraphql.
I found the example written in graphql-tools about "deep-level mutations". And I found it so useful, but I don't understand how I can write it using typegraphql library.
Example in graphql-tools:
const typeDefs = gql`
type Query { ...}
type Post { ... }
type Mutation {
likePost(id: Int!): LikePostPayload
}
type LikePostPayload {
recordId: Int
record: Post
# ✨✨✨ magic – add 'query' field with 'Query' root-type
query: Query!
}
`;
const resolvers = {
Mutation: {
likePost: async (_, { id }, context) => {
const post = await context.DB.Post.find(id);
post.like();
return {
record: post,
recordId: post.id,
query: {}, // ✨✨✨ magic - just return empty Object
};
},
}
};
I found it useful because you can structure your API as it structured in GitHub GraphQL API
I just want to someone re-write it and show in comments and explain where I can find more information.
Thank you.
PS: Sorry if is it a easy question, but I didn't find any info about it, and sorry about my English, I'm not a native speaker.
I don't see this pattern useful. When your mutation changes something, you should return the mutated resources, not force the users to perform a nested query to read again the mutated resource.
So as your query don't rely on the changed resource, you can just perform the query operation as it doesn't depend on the mutation.
Closing for a housekeeping purposes 🔒
Most helpful comment
I don't see this pattern useful. When your mutation changes something, you should return the mutated resources, not force the users to perform a nested query to read again the mutated resource.
So as your query don't rely on the changed resource, you can just perform the query operation as it doesn't depend on the mutation.