EmbedGitHub'sGraphQLAPIintoyourserverapplication
DeprecationNotice!Inthelastfewmonths,sincethetransitionofmanylibrariesunderTheGuild'sleadership,We'vereviewedandreleasedmanyimprovementsandversionstographql-cli,graphql-configandgraphql-import.
We'vereviewedgraphql-binding,hadmanymeetingswithcurrentusersandengagedthecommunityalsothroughtheroadmapissue.
Whatwe'vefoundisthatthenewGraphQLMeshlibraryiscoveringnotonlyallthecurrentcapabilitiesofGraphQLBinding,butalsothefutureideasthatwereintroducedintheoriginalGraphQLBindingblogpostandhaven'tcometolifeyet.
Andthebestthing-GraphQLMeshgivesyouallthosecapabilities,evenifyoursourceisnotaGraphQLserviceatall!itcanbeGraphQL,OpenAPI/Swagger,gRPC,SQLoranyothersource!AndofcourseyoucanevenmergeallthosesourcesintoasingleSDK.
JustlikeGraphQLBinding,yougetafullytypedSDK(thankstotheprotocolsSDKsandtheGraphQLCodeGenerator),butfromanysource,andthatSDKcanrunanywhere,asaconnectororasafullblowngateway.Andyoucanshareyourown"MeshModules"(whichyouwouldprobablycall"yourownbinding")andourcommunityalreadycreatedmanyofthose!Also,wedecidedtosimplyexposeregularGraphQL,soyoucanchoosehowtoconsumeitusingalltheawesomefluentclientSDKsoutthere.
Ifyouthinkthatwe'vemissedanythingfromGraphQLBindingthatisnotsupportedinabetterwayinGraphQLMesh,pleaseletusknow!
Installyarnaddgraphql-binding-githubExample(Demo)Seeexampledirectoryforfullexampleapplication.
const{GitHub}=require('graphql-binding-github')const{GraphQLServer}=require('graphql-yoga')const{importSchema}=require('graphql-import')constfavoriteRepos=[{owner:'graphcool',name:'graphql-yoga'},{owner:'graphql',name:'graphql-js'},]consttoken='__ENTER_YOUR_GITHUB_TOKEN__'constgithub=newGitHub(token)consttypeDefs=importSchema('schemas/app.graphql')constresolvers={Query:{hello:(parent,{name})=>`Hello${name||'World'}!`,favoriteRepos:(parent,args,context,info)=>{returnPromise.all(favoriteRepos.map(args=>github.query.repository(args,context,info)),)},},//thefollowingisneededtomakeinterfaces,unions&customscalarswork...github.getAbstractResolvers(typeDefs),}constserver=newGraphQLServer({resolvers,typeDefs})server.start(()=>console.log('Serverrunningonhttps://localhost:4000'))HowtocreateaGitHubTokenSimplyfollowthisguideandheadovertothetokensettingsonGitHub.
ResourcesGithubGraphQLExplorer:https://developer.github.com/v4/explorer/
评论