graphql-compose icon indicating copy to clipboard operation
graphql-compose copied to clipboard

Types from Swagger schema

Open yarax opened this issue 8 years ago • 4 comments

Hi! I've released a https://github.com/yarax/swagger-to-graphql library and probably it can be somehow adopted for graphql-compose, but now the goal of swagger-to-graphql is to migrate REST API to GraphQL completely automatically. So if you have any collaboration ideas just let me know

yarax avatar Oct 16 '16 14:10 yarax

Yep, I have some ideas. But need some time to complete some urgent things for my internal product. Also I should read your article about swagger-to-graphql: https://medium.com/@raxwunter/moving-existing-api-from-rest-to-graphql-205bab22c184#.azvi73oh2

nodkz avatar Oct 17 '16 04:10 nodkz

The main goal of graphql-compose help you to build a complex schema from different sources. For this purpose, it has 4 main classes:

  • TypeComposer - can manipulate by GraphQLObjectType. Add/get/remove fields and store additional useful stuff, eg a list of Resolvers.
  • InputTypeComposer - manipulates by GraphQLInputObjectType.
  • Resolver - consists from outputType, args and resolve method. In terms of GraphQL, it is FieldConfig.
  • GQC - type storage with schema builder (has rootQuery and rootMutation methods which return TypeComposer, which allows add fields to Query and Mutation.

So right not exists graphql-compose-mongoose package, which can take one Mongoose model and return TypeComposer with 13 Resolvers (findById, findMany, count updateOne and others). So it allows to developer use this resolvers as wish. Eg. add only two resolvers to rootQuery

GQC.rootQuery().addFields({
  userFindById: UserTC.getResolver('findById'),
  userFindMany: UserTC.getResolver('findMany'),
})

Will be cool if you create analogous way a package graphql-compose-swagger. Which will have a method that gets some options and returns one TypeComposer for some resource. Eg. Pet with 7 Resolvers according to swagger schema (addPet, updatePet, findPetsByStatus, findPetsByTags, getPetById, updatePetWithForm, deletePet): screen shot 2016-10-20 at 15 38 16 This granularity allows to add your schema only that what you want with adding aditional logic to resolvers (eg. access restriction).

Of course, your package can expose other methods which return lists of TypeComposers from the swagger schema and helps automatically build schema. Or method that completely automatically build schema.

nodkz avatar Oct 20 '16 10:10 nodkz

Cool, thanks for detailed explanation. Flexibility is always good. Created an issue for that.

yarax avatar Oct 20 '16 14:10 yarax

Hey,

JFI: In our company we have swagger and graphql set as some kind of standard. This situation was some kind of historically grown and cannot be changed. So we ended up to use swaggerjs https://github.com/swagger-api/swagger-js to make calls straight out of the resolvers. This was the only approach we found to bring both worlds together. It would be fantastic to have some kind of solution like swagger-to-graphql and then composing up the services together to another GraphQL service.

TimSusa avatar Jun 15 '18 17:06 TimSusa