sikanhe / gqtx

Code-first Typescript GraphQL Server without codegen or metaprogramming
458 stars 13 forks source link

extending types #2

Closed n1ru4l closed 4 years ago

n1ru4l commented 4 years ago

I usually try to split up my schema into modules. Is there any way for adding fields to the Query or Mutation types from within another file?

sikanhe commented 4 years ago

is it possible to define the fields in another file and import them? I can also add a "addField(type, field) function, but I think we can already accomplish that by importing types/fields from another file

n1ru4l commented 4 years ago

That is the way I went for and I am fine with it for now! Only drawback is circular refs if you try to return the Query type from another field.

cjol commented 3 years ago

My use-case involves schema-stitching, and so I would like the schema output to include extend type Query { ... }. The main query definition comes from an external schema so I can't just import the fields.

Is there some other way to do that?

n1ru4l commented 3 years ago

@cjol I guess that is a use-case for https://github.com/ardatan/graphql-tools

cjol commented 3 years ago

I was unclear, sorry. I'm using schema-stitching, using graphql-tools. My problem is that one schema is defined externally, and the other is defined by gqtx. I would like to include extend type Query { ... } inside the schema generated by gqtx so that graphql-tools can stitch the schemas corectly.

Right now, all I can do is use t.queryType({...}) which generates type Query { ... } without the extend keyword. Seeing this, the schema-stitching process will overwrite the other schema's Query definition instead of augmenting it.