Hello guys, how can I obtain typescript interfaces...
# orm-help
m
Hello guys, how can I obtain typescript interfaces for custom schema types (specifically mutation payload) defined in
schema.graphql
?
j
hey @michal.tomsia You can looks around
graphql-binding
directly
create a file
src/schema.ts
with:
Copy code
import * as path from 'path'
import { makeExecutableSchema } from 'graphql-tools'
import { importSchema } from 'graphql-import'

// This is only used for generating `src/binding.ts`
export default makeExecutableSchema({
  typeDefs: importSchema(path.resolve('src/schema.graphql')),
  resolverValidationOptions: {
    requireResolversForResolveType: false,
  },
})
then create this scripts into your package.json
"graphql-types": "npx graphql-binding --input src/schema.ts --language typescript --outputBinding src/binding.ts"
and you will just need to make a
npm run graphql-types
after each deploy
(or even use post-hook)
m
will try, thanks for the quick response 🙂
j
and in your resolver you will be able to make some:
Copy code
import { UserWhereUniqueInput } from '../binding'
u’re welcome
let me know if you have some problems about it
👌 1
m
your answer gave me a clue and I was able to achieve goal with simple modification in
.graphqlconfig.yml
Copy code
codegen:
        output:
          binding: src/generated/schema.ts
        generator: prisma-binding
        language: typescript
under the
projects.app.extensions
key
j
this part is to generate the
prisma.ts
example:
Copy code
prisma:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: prisma/prisma.yml
      codegen:
      - generator: prisma-binding
        language: typescript
        output:
          binding: src/generated/prisma.ts
m
yeah I know, I left the
prisma.ts
generation but added additional
codegen
for
schema.ts
j
but like you say, the TS interface create to match with
prisma.graphql
can be different of what you have inside the
src/schema.graphql
ah
what is the
schemaPath
in the code you pasted?
m
src/schema.graphql
j
hum... I see
and it works? 😄
m
yeah 😄
j
because it will be simpler that my method (that I already take from another github repo)
nice
I will try to take a look during the weekend (I will be off the next week) and try both generator
graphql-binding
and
prisma-binding
to see if there have difference
m
but I guess it duplicates the types from
prisma.ts
which is wrong
j
it’s depend if you have some “import” like =>
#import User from 'src/generated/prisma.graphql
m
right