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

Methods not included when using 'extend' #19

Open
jahredhope opened this issue Feb 3, 2019 · 2 comments · May be fixed by #44
Open

Methods not included when using 'extend' #19

jahredhope opened this issue Feb 3, 2019 · 2 comments · May be fixed by #44

Comments

@jahredhope
Copy link

jahredhope commented Feb 3, 2019

Firstly, thanks for this tool. It's been really great to have my resolvers strongly typed with minimal effort. I've recently been trying out a new modular pattern which has led me to a problem.

Problem

When I use extend to break up my type definitions I don't see the extended values in the type.

Example

Prior to splitting the modules out I have a TypeScript type that accurately describes the resolvers for Query.

type Dog {
  imageUrl: String!
}

type Query {
  dogs(limit: Int): [Dog!]
}
export interface GQLQueryTypeResolver<TParent = undefined> {
  dogs?: QueryToDogsResolver<TParent>;
}

But as I want to add more to the schema I look to add something like:

type Cat {
  imageUrl: String!
}

type Query {
  cats(breed: String!, limit: Int): [Cat!]
}

Which of-course isn't valid, as I've now defined Query twice.

To keep the code nice and clean I give the Query a base definition, and use extend in the seperate modules:

type Query {
  _empty: String
}
extend type Query {...

However, now the Query definition shows only _empty and not the extended values:

export interface GQLQueryTypeResolver<TParent = undefined> {
  _empty?: QueryTo_emptyResolver<TParent>;
}

Ideal

Ideally I want to see something like below. Is this possible? If not is there a reason the extended types shouldn't be concatenated together?
If it's not currently possible, and it's not a terrible idea would you be open to a PR?

export interface GQLQueryTypeResolver<TParent = undefined> {
  _empty?: QueryTo_emptyResolver<TParent>;
  cats?: QueryToCatsResolver<TParent>;
  dogs?: QueryToDogsResolver<TParent>;
}
@jahredhope
Copy link
Author

For anyone else having this issue above my solution was to parse then print the schema as below:

import { printSchema } from "graphql";
import { buildSchemaFromTypeDefinitions } from "graphql-tools";

const typeDefs = printSchema(buildSchemaFromTypeDefinitions(typeDefs));

generateTypeScriptTypes(typeDefs, "types.ts");

@dangcuuson
Copy link
Owner

Hi there, I'm glad that you like this tool.

Just to clarify, is your 2nd post means the tool is working?

If possible could you describe how you used it in the first post that make this error.

@ruiaraujo ruiaraujo linked a pull request Mar 22, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants