question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutoSchema, is it possible to combine (merge) queries or mutations from several classes?

See original GitHub issue

Hello,

I found that AddAutoSchema was very useful for the code-first approach, but I found it not so clean to make a class contains all of the queries (and also for mutations). When number of queries and mutations grows it’s a little bit hard to manage the code.

Is it possible to group them for something like this?

public class UserQuery 
{
    IList<User> Users(int limit, int offset) {}
    IList<User> User(int id) {}
}

public class UserMutation 
{
    User CreateUser(User user) {}
    User UpdateUser(int id, User user) {}
    bool DeleteUser(int id) {}
}

public class PostQuery 
{
    IList<Post> Posts(int limit, int offset) {}
    IList<Post> Post(int id) {}
}

public class PostMutation 
{
    Post CreatePost(Post post) {}
    Post UpdatePost(int id, Post post) {}
    bool DeletePost(int id) {}
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Shane32commented, Jun 23, 2022

You can also do without the IQuery and etc a bit more simply:

public class Query : ObjectGraphType
{
    public Query()
    {
        AddFields<UserQuery>();
        AddFields<PostQuery>();

        void AddFields<T>()
        {
            var graphType = new AutoRegisteringObjectGraphType<T>();
            foreach (var field in graphType.Fields)
                AddField(field);
        }
    }
}

I didn’t test all this code, but I think it will work.

0reactions
ktutnikcommented, Jun 23, 2022

Ah, I think I understand the idea. Thank you guys for the variety of answers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to combine a mutation and a query in a single query?
There's no way to send a mutation and a query in one request according to the GraphQL specification. However, you can add any...
Read more >
Auto schema generation · Issue #49 · graphql-python ...
This only currently generates a schema with queries, not mutations. I haven't fired it up in over a year. I hope it helps....
Read more >
GraphQL schema basics
A single mutation operation can include multiple top-level fields of the Mutation type. This usually means that the operation will execute multiple back-end ......
Read more >
How to Combine GraphQL Type Definitions Quickly and ...
Let's do it! You can escape a giant file like this with Queries + Mutations of different resource types lobbed together!
Read more >
How to run multiple GraphQL queries and combine ...
This means you can combine data from various sources into your project so you can query them at once through your GraphQL API....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found