prisma-labs / graphqlgen

⚙️ Generate type-safe resolvers based upon your GraphQL Schema
MIT License
817 stars 56 forks source link

Supporting modularized graphql schemas #201

Open adamalfredsson opened 5 years ago

adamalfredsson commented 5 years ago

I keep my graphql schemas and models in a modular file structure:

src/ —modules/ ——user/ ———user.graphql ———user.model.ts ——post/ ———post.graphql ———post.model.ts

My graphqlgen.yml

language: typescript

schema: ./src/modules/**/*.graphql
context: ./src/typings/schema.d.ts:Context
models:
  files:
    - ./src/modules/**/*.model.ts

output: ./src/generated/graphqlgen.ts

resolver-scaffolding:
  output: ./src/generated/tmp-resolvers/
  layout: file-per-type

throws: 'The schema file ./src/modules/*/.graphql does not exist'

schickling commented 5 years ago

Can you share an example repo where you’re following this structure?

adamalfredsson commented 5 years ago

I guess this would be a valid example repo: https://github.com/benawad/graphql-ts-server-boilerplate

stephenh commented 5 years ago

@nomadoda we're using (prototyping) graphqlgen with a patched graphql-import that I believe would support your structure with schema: ./src/modules/:

https://github.com/prisma/graphql-import/pull/246

The trailing / on ./src/modules/ tells the patched graphql-import to just recursively scan for *.graphql files and concatenate them together.

sidroopdaska commented 5 years ago

@schickling @stephenh is the above working?

I tried running graphqlgen with the following .yml file and I keep getting:

Error occurred while reading schema: Syntax Error: Cannot parse the unexpected character ".".

GraphQL request (1:1)
1: ./src/modules/
   ^

My graphqlgen.yml is as follows:

language: typescript

schema: ./src/modules/
context: ./src/model.ts:Context
models:
  files:
    - ./src/modules/feeds/model.ts
    - ./src/modules/user/model.ts

output: ./src/generated/graphqlgen.ts

resolver-scaffolding:
  output: ./src/generated/tmp-resolvers/
  layout: file-per-type

Lastly, are there any graphqlgen api's that I can call from a script to generate the resolver types (i.e. graphqlgen.ts) and their bolierplate for each of these modules separately rather having to constantly go and edit the graphqlgen.yml. This would be quite useful for build time.

Inoir commented 5 years ago

@sidroopdaska the above is not working, except you using the patched version from @stephenh of the graphql-import lib. Problem currently is, graphql-import only accepts .graphql files. If you merge your schemas with graphql-tools and want to import i.E .ts file. the error you described appears.

Simple sulotion for schema stitching would be to allow also other file extensions in the graphql-import lib.