Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GoでGraphQLサーバを立てるぞ! / Building GraphQL server b...

GoでGraphQLサーバを立てるぞ! / Building GraphQL server by go

mercari.go #2 登壇資料です
https://mercari.connpass.com/event/95665/

Masahiro Wakame

August 10, 2018
Tweet

More Decks by Masahiro Wakame

Other Decks in Technology

Transcript

  1. GraphQLͬͯԿʁ RESTͳΒ3RPCඞཁ
 GraphQLͳΒ1ճ { circle(id: "Q2lyY2xlRXhoaWJpdEluZm86MTIzNAo") { name spaces penName

    webSiteURL genre genreFreeFormat products(first: 9) { pageInfo { hasNextPage endCursor } nodes { name description type page price relatedURLs firstAppearanceEventName firstAtTechBookFest images { url height width } } } loginUserChecked { checked } } }
  2. ϝϧΧϦͰ࢖ͬͯΔʁ •C Sπʔϧ PHP+webonyx/graphql-php •US ϝϧΧϦWeb ??? •MicroserviceԽ CSπʔϧ Go+gqlgen

    •ϝϧΧϦWeb Node.js+Apollo •ϝϧϖΠ CSπʔϧ(ݕ౼த) Go+gqlgen ٕज़ॻయWeb΋࣮ݧதͰ͢
  3. Queryͷྫ { viewer { id login name location bio company

    repositoriesContributedTo(first: 2) { nodes { owner { login } name } } } } { "data": { "viewer": { "id": "MDQ6VXNlcjEyNTMzMg==", "login": "vvakame", "name": "Masahiro Wakame", "location": "Tokyo, Japan", "bio": "TypeScript and GAE/Go", "company": "Merpay, Inc.", "repositoriesContributedTo": { "nodes": [ { "owner": { "login": "mruby" }, "name": "mruby" }, { "owner": { "login": "DefinitelyTyped" }, "name": "DefinitelyTyped" } ] } } } } ରԠͨ͠ߏ଄͕ฦΔ
  4. ͬ͘͟ΓServerݪཧ type ResolverRoot interface { Query() QueryResolver User() UserResolver CircleExhibitInfo()

    CircleExhibitInfoResolver ProductInfo() ProductInfoResolver } type QueryResolver interface { Circle(ctx context.Context, id string) (*CircleExhibitInfo, } type CircleExhibitInfoResolver interface { ID(ctx context.Context, obj *CircleExhibitInfo) (string, err Products(ctx context.Context, obj *CircleExhibitInfo, first } type ProductInfoResolver interface { ID(ctx context.Context, obj *ProductInfo) (string, error) Images(ctx context.Context, obj *ProductInfo) ([]Image, erro } query { circle(id: "Q2lyY2xlRXhoaWJpdEluZm86MTIzNAo") { name spaces penName webSiteURL genre genreFreeFormat products(first: 9) { pageInfo { hasNextPage endCursor } nodes { name description type page price relatedURLs firstAppearanceEventName firstAtTechBookFest images { url height width } } } loginUserChecked { checked } }
  5. REST APIͱͷରൺ •REST API = RPC •GraphQL = QueryLanguage •Τϥʔʹର͢Δߟ͑ํ͕ࠜຊతʹҧ͏

    •“ਖ਼͍͠Requestͷ౤͛ํ” ͱ͍͏֓೦ •ڻ͖࠷খͷݪଇ & σόοΨϏϦςΟ