I would like to be able to have my queries/mutations in separate files and merge them while generation. I see that there is schema stitching, which i do use, but is there anyway i can have query type in more than one file and merge them together?
Thanks!
This is already supported - you can provide multiple schema files in the gqlgen config, see https://gqlgen.com/config/ for more details
hi @lwc i tried having two schemas with type Query in them and i get
modelgen: privsector.graphql: Cannot redeclare type Query.
This is how i have my gqlgen.yaml file:
schema:
- geojson.graphql
- schema.graphql
- privsector.graphql
And this is how i try to generate:
func main() {
fmt.Fprintln(os.Stderr, "Generating graphql code ...")
log.SetOutput(os.Stderr)
config, err := config.LoadConfigFromDefaultLocations()
if err != nil {
die("load config: %v", err)
}
if err = api.Generate(config); err != nil {
die("codegen: %v", err)
}
fmt.Fprintln(os.Stderr, "Done generating graphql code.")
}
These are my schemas:
type SampleType{
sample: String
}
type Query {
querySampleA: SampleType
}
type Query {
querySampleB: SampleType
}
In order to have a valid schema across multiple files you need to use Type extensions
So define your main Query type somewhere, then in your other files:
extend type Query {
// additional fields
}
Thank you! that worked!! 馃挴
What about having an interface type defined in one schema file, and implementing it in the other? Does give me a undefined type at the moment?
Most helpful comment
In order to have a valid schema across multiple files you need to use Type extensions
So define your main
Querytype somewhere, then in your other files: