Is your feature request related to a problem? Please describe.
i am working a schema in a monolithic app with huge schema which make searching for a specific type to edit very frustrating
Describe the solution you'd like
it would be better if i can split the schema file into multiple smaller one each with specific purpose without having to split into multiple services and use schema stitching
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
You can do that. Just add multiple files to the schema. You can do that with code first and with schema first.
You can even split your types.
type Query {
a: String
}
extend type Query {
b: String
}
Oh i didn't know that, thank you for the quick answer
feel free to close the issue but i think this should go in the documentation as it is not clear from the documentation
I'm looking to do something like this as well. I'm still somewhat new to graphql so correct me if I'm doing this wrong. However I'm creating TodoQuery object which will handle all the queries for my Todo entities, and I was going to create another for Account queries AccountQuery and for Group queries GroupQuery however when I try to add more than one query to the schema I get dependency injection issues. So my question is how does is this supposed to work with code first?
Here is the line of code I'm commenting out to get it to run one query at a time.
https://github.com/honey-dos/web/blob/feature/graphql-hot-chocolate/HoneyDo.Web/GraphQL/HoneyDosSchema.cs#L15
GraphQL is as the name says a graph 😄
This means you can only have one root type for queries, this type is what Hot Chocolate refers to as the "Query Type".
What @michaelstaib and @husseinraoouf are talking about is how you can break down the organization in some way to make your code base more manageable. For code first you can do much as same with type extensions.
First we'll create our root query type, this is the one we'll use with AddQueryType.
public class QueryType : ObjectType
{
}
We can then do the code first equivalent of extend type Query and add our Account fields.
``` csharp
public class AccountQueryTypeExtension : ObjectTypeExtension
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor.Name("Query");
descriptor.Field("accounts"); // normal field declaration continues here.
}
}
````
You'll need to add AccountQueryTypeExtension to your schema for it to be used.
This means you can break your top level fields across a number of classes for better code organization.
@nigel-sampson exactly right. With 10.3.0 you can even now have Model bound extensions. ObjectTypeExtension
I see. I've got a working example. Is there an easy way to use descriptor.Include<TResolver>() and enable .Authorize() just on that included resolver?
Yes with version 10.3.0 this will become easy.
@michaelstaib i have tried to splitting type definition as you suggested in your comment but it doesn't work, may be i am doing something wrong
here is what i am doing
in Startup.cs
```c#
services.AddGraphQL(sp => SchemaBuilder.New()
.AddServices(sp)
.AddDocumentFromFile("Schema/schema.graphql")
.AddDocumentFromFile("Schema/User/schema.graphql")
// emitted code
Schema/schema.graphql
```graphql
type Query {
"""
Hello World Query
"""
hello(name: String = "World"): String!
}
type Mutation {
hello(name: String = "World"): String!
}
Schema/User/schema.graphql
extend type Query {
helloTwo(name: String = "World"): String!
}
extend type Mutation {
helloTwo(name: String = "World"): String!
}
i have tried with v 10.2.0 and v 11.0.0-preview.58
i also tried to use extend in the main schema file Schema/schema.graphql and it also didn't work
I will check your code later.