Gqlgen: Using prisma generated inputs

Created on 26 Mar 2019  路  4Comments  路  Source: 99designs/gqlgen

Is there yet a way to use prisma generated inputs as input types for graphql? For example I have a user in datamodel.prisma like so:

type User {
  id: ID! @unique
  name: String!
  email: String! @unique
  password: String!
  resetToken: String
  resetTokenExpiry: Float
  createdAt: DateTime!
  updatedAt: DateTime!
}

which prisma uses to generate a bunch of functions, and say I want to make an updateUser mutation with the prisma generated struct as the input in schema.graphql.
The struct:

type UserUpdateInput struct {
    Name             *string  `json:"name,omitempty"`
    Email            *string  `json:"email,omitempty"`
    Password         *string  `json:"password,omitempty"`
    ResetToken       *string  `json:"resetToken,omitempty"`
    ResetTokenExpiry *float64 `json:"resetTokenExpiry,omitempty"`
}

At the moment I have to recreate the UserUpdateInput in schema.graphql which is fine since the User type is comprised of nothing but scalars, however for other types the inputs are other prisma generated input types, for example:

type ArticleUpdateInput struct {
    Title       *string                                      `json:"title,omitempty"`
    Body        *ArticleBodyUpdateOneWithoutArticleInput     `json:"body,omitempty"`
    Author      *AuthorUpdateManyWithoutArticlesInput        `json:"author,omitempty"`
    Source      *SourceUpdateOneRequiredWithoutArticlesInput `json:"source,omitempty"`
    Url         *UrlUpdateOneRequiredInput                   `json:"url,omitempty"`
    Entities    *EntityUpdateManyWithoutArticlesInput        `json:"entities,omitempty"`
    Sentiment   *float64                                     `json:"sentiment,omitempty"`
    PublishedAt *int32                                       `json:"publishedAt,omitempty"`
}

Is there a way around redefining every input type I want to use in schema.graphql?

enhancement stale

Most helpful comment

I'm very interested in this

All 4 comments

So what you're really asking is if there is a way to somehow generate GraphQL input types from your Go types? Currently there isn't, but it could potentially be implemented as a plugin; a sort-of reverse schema-gen. gqlgen is primarily schema-first though, so I don't see this feature being implemented in the core, but it could be a contrib feature.

I'm very interested in this

Me too. Any plans on making this happen? I can help contribute if necessary.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cemremengu picture cemremengu  路  3Comments

bjm88 picture bjm88  路  4Comments

lynntobing picture lynntobing  路  3Comments

jwatte picture jwatte  路  4Comments

steebchen picture steebchen  路  3Comments