graphql-compose
graphql-compose copied to clipboard
Types from Swagger schema
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
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
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
andresolve
method. In terms of GraphQL, it is FieldConfig. -
GQC - type storage with schema builder (has
rootQuery
androotMutation
methods which returnTypeComposer
, which allows add fields toQuery
andMutation
.
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):
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.
Cool, thanks for detailed explanation. Flexibility is always good. Created an issue for that.
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.