Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema first from multiple files #2109

Closed
zivfuture opened this issue Jul 7, 2020 · 8 comments
Closed

schema first from multiple files #2109

zivfuture opened this issue Jul 7, 2020 · 8 comments
Labels
❓ question This issue is a question about feature of Hot Chocolate.

Comments

@zivfuture
Copy link

I tried to split graqhql language code in multiple files like this:

a.graphql:
type Query{
hello: String!
}

b.graphql:
type Query{
hi: String!
}

and typed code like this in gateway, but i get an error
" HotChocolate.SchemaException:“The name Query was already registered by another type. - Type: Query":

services.AddGraphQL(sp => SchemaBuilder.New()
.AddDocumentFromFile("a.graphql")
.AddDocumentFromFile("b.graphql")
.BindComplexType()
.Create());

@zivfuture
Copy link
Author

anyone can help ?

@vbornand
Copy link
Contributor

vbornand commented Jul 7, 2020

If you define the same type in multiple files, you have to add extend before the type definition in the b.graphql file.

a.graphql:

type Query{
  hello: String!
}

b.graphql:

extend type Query{
  hi: String!
}

More details about this : https://www.apollographql.com/blog/modularizing-your-graphql-schema-code-d7f71d5ed5f2

@zivfuture
Copy link
Author

If you define the same type in multiple files, you have to add extend before the type definition in the b.graphql file.

a.graphql:

type Query{
  hello: String!
}

b.graphql:

extend type Query{
  hi: String!
}

More details about this : https://www.apollographql.com/blog/modularizing-your-graphql-schema-code-d7f71d5ed5f2

Thanks for reply.
I do as you said and get a new error:
{
"errors": [
{
"message": "The field hi does not exist on the type Query.",
"locations": [
{
"line": 7,
"column": 5
}
]
}
]
}

@vbornand
Copy link
Contributor

vbornand commented Jul 7, 2020

I think you have another issue.

This following code works:

class Program
    {
        static void Main(string[] args)
        {
            var sb = SchemaBuilder.New().AddDocumentFromFile("a.graphql")
            .AddDocumentFromFile("b.graphql")
            .AddResolver("Query", "hi", "Earth")
            .AddResolver("Query", "hello", "World")
            .Create();

            var r = sb.MakeExecutable().Execute("{ hi\nhello\n }");
            Console.WriteLine(r.ToJson());
        }
    }

Result:

{
  "data": {
    "hi": "Earth",
    "hello": "World"
  }
}

Can you please share more code or create a github repo with your code?

@michaelstaib
Copy link
Member

We haven’t support for extend on sdl first yet. There is however a big update coming to sdl first. We will soon start discussing sdl first in v11

@michaelstaib
Copy link
Member

Join our slack channel

@michaelstaib
Copy link
Member

Closing this issue since splitting types in sdl first is not supported in 10

@michaelstaib michaelstaib added 🌶 hot chocolate ❓ question This issue is a question about feature of Hot Chocolate. labels Jul 7, 2020
@oising
Copy link
Contributor

oising commented Feb 5, 2021

Is it supported for v11?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question This issue is a question about feature of Hot Chocolate.
Projects
None yet
Development

No branches or pull requests

4 participants