Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Missing custom types properties in suggested model types. #448

Open
otrebu opened this issue Feb 11, 2019 · 7 comments
Open

Missing custom types properties in suggested model types. #448

otrebu opened this issue Feb 11, 2019 · 7 comments

Comments

@otrebu
Copy link

otrebu commented Feb 11, 2019

My schema.graphql contains:

type Post {
    id: ID!
    title: String!
    content: String!
    comments: [Comment!]
    user: User!
}

When I generate the types the suggested type for Post is:

export interface Post {
    id: string;
    title: string;
    content: string;
    isAvailable: boolean;
}

I am not sure why comments and user are missing?

Steps to reproduce

Expected results

Actual results

Versions

  • graphqlgen:
  • OS name and version:
@jasonkuhrt
Copy link
Member

jasonkuhrt commented Feb 11, 2019

Hey @otrebu, these model types represent what your server will fetch from the backend(s) (DB, microservice, etc). A model type is something that a resolver implementation can return. The missing types you pointed out are relations. What would you ideally expect graphqlgen to generate for you?

@otrebu
Copy link
Author

otrebu commented Feb 12, 2019

Hi @jasonkuhrt yes they are relations, but is it not normal to want to return them?

Otherwise the strongly typing becomes a pain, as you return they prisma type which contains the relations as promises, which will be resolved anyway.
(This is where I experienced that weirdness that I shared in slack).

So personally I would expect them to be part of the types returned by graphqlgen.

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Feb 12, 2019

What if a query field resolver fetches it’s scaler data from one backend data source but fetches the relations from another source. A model maps to/specifies what the return value of some resolver will be. Resolvers should do as little work as possible. If client doesn’t include comments in selection set then server should not wastefully fetch them—to encode this in model types means keeping type relations at best shallow (list of comment IDs, author I’d, etc.

I need to make a diagram for this.

@jasonkuhrt
Copy link
Member

we might want to merge this thread into #181

@otrebu
Copy link
Author

otrebu commented Feb 12, 2019

@jasonkuhrt is it not what the resolvers on a type, for a specific field are for?

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Feb 12, 2019

is it not what the resolvers on a type, for a specific field are for?

If you can, take a look at the generated resolver types:

  • root field resolvers are (generally) expected to return models (but can, of course, return scalers if the schema is setup that way)
  • non-root field resolvers receive models as parent
  • field resolvers, that are schema relations, are expected to return models

@otrebu
Copy link
Author

otrebu commented Feb 13, 2019

Hi @jasonkuhrt, I think I must have been taking a wrong approach and got confused when using it with prisma. You probably don't need them...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants