muuki88 / sbt-graphql

SBT plugin to generate and validate graphql schemas written with Sangria
Apache License 2.0
96 stars 20 forks source link

fixed stackoverflow error, running in tests, json encoding #71

Closed Krever closed 5 years ago

Krever commented 5 years ago

Hey, this is rather uncannonical PR with various changes. Its this way because I was fixing various things as I was trying to use the plugin. I dont expect the PR to be merged right away but submitting anyway :) Maybe will be of some use to someone.

Changes made:

  1. recursive use of types cause stack overflow error in touchType method (TypedDocumentParser.scala). This is probably least controversial change and can be cherrypicked right away.
  2. I added json encoders to all the types generated. Its not an optimal solution as encoders are only needed for types included in Variables but it was easier to add it everywhere. Relates to #35
  3. I modified the sbt part in a way that allows to use the codegen in both Compile and Test configuration. From user perspective the change shouldnt be visible as the default graphqlCodegen defaults to compile:graphqlCodegen but now test:graphqlCodegen has also a meanigful implementation that takes queries from test sources and produces output to test results. The only problem I have hit is that Interfaces files clashes (you have 2 of those, one for prd and one for test). It wasnt an issue for my particular case because I need it only in tests.