Graphcool / graphcool-framework

Apache License 2.0
1.77k stars 131 forks source link

Adding a template to a project with multiple type files merges all types into one file #430

Open marktani opened 6 years ago

marktani commented 6 years ago

Issue by grahamb Friday Dec 01, 2017 at 23:57 GMT Originally opened as https://github.com/graphcool/prisma/issues/1356


Current behavior

When adding a template to a project that has multiple type definition files defined in graphcool.yml, the graphcool add-template command merges all type definitions into the first file defined in the types list.

Reproduction

  1. Create a new graphcool project.
  2. Create multiple types files and list them under types in graphcool.yml
    types:
    - ./types/Authors.graphql
    - ./types/Posts.graphql
  3. Add a template using graphcool add-template (e.g. graphcool add-template graphcool/templates/auth/auth0
  4. Open ./types/Authors.graphql. Notice that the contents of Posts.graphql and the commented-out types from the auth0 template have been added to Authors.graphql

Expected behavior?

I can see two possible options in a project with multiple type files:

  1. Append the imported types to the first file in the list, but do not append the other types from the project.
  2. Create a new types file named after the template. This could be difficult becuase there is no standard file structure defined by Graphcool – where would it put the file? Project root is probably the safest. Given that types are added commented-out, the new file could be added commented-out to the types list as well, or just left to the developer to add manually.