Closed Industrial closed 5 years ago
Thanks @Industrial! Can you please share your schema (json/file)? Or a repository with a reproduction? thanks!
@dotansimha I guess the ./common/domain/datamodel.graphql
looks something like this (took from here):
type Post {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
isPublished: Boolean! @default(value: "false")
title: String!
content: String!
author: User!
}
type User {
id: ID! @unique
name: String!
email: String! @unique
posts: [Post!]!
createdAt: DateTime!
updatedAt: DateTime!
}
I think @Industrial removes directives and what's left is:
type Post {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
isPublished: Boolean!
title: String!
content: String!
author: User!
}
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
createdAt: DateTime!
updatedAt: DateTime!
}
So DateTime
is not defined as a scalar
@Industrial I guess you can define DateTime
scalar in the codegen and it should work, just like here https://github.com/dotansimha/graphql-code-generator/pull/444
@kamilkisiela This is what I get now: https://gist.github.com/Industrial/a8135cc5f259aacf8c169efc37768d90
@Industrial I think you don't need to define ID
explicitly.
If I leave out the ID scalar then I get the same error on ID
@ardatan, @kamilkisiela: I'm not sure what to do with the ticket that @kamilkisiela pointed to.
He mentioned the "codegen". This is the domainmodel.graphl
(or a URI) I'm using for the source? Or is there a configuration file that I should put data types like DateTime and ID in?
What you have is prisma config, not GraphQL Schema with queries, mutations and subscriptions, something that GraphQL server expects. GraphQL Codegen can't guess how you're data looks like so what you might eventually get is just a typescript interface for a model, no queries and other prisma generated things. If you would point gql-gen
to server's endpoint or a file with introspection result it'd generate everything for you.
@Industrial can you put up a small repo with an example? that way someone can make a nice PR and demonstrate how to do it
Not sure if this is still an issue, but if I understood it correctly @Industrial you don't want to be generating types from your datamodel like that.
If you want types for resolvers, you first need to generate the schema (the one you pass to the server) and then you can generate types for that schema.
If you want types for your prisma (datamodel) you can do so using post hooks in prisma.yml
and .graphqlconfig
https://www.prisma.io/docs/prisma-cli-and-configuration/prisma-yml-5cy7/
WHoa, @nemcek, I didn't know prisma had code generation itself :S. It seems they just released it. I'm closing this, then. Thanks for your time.
Hi!
I am using Prisma to serve GraphQL. It uses annotations on top of graphql. It also uses some types like
DateTime
andID
.I tried this NPM script to take out the annotations:
But that only takes out the annotations, I still don't know what to do with the types:
Right now when I run
gql-gen --schema ./common/domain/datamodel-no-annotations.gen.graphql --template graphql-codegen-typescript-apollo-template --out ./common/domain/entities
I get errors likeerror: Field timestamp: Couldn't find type DateTime in any of the schemas.
orerror: Cannot read property 'ID' of undefined
.