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

GraphQL and Schema-First Development

GraphQL and Schema-First Development

GraphQL NightでのLT発表資料です

Kōhei Yamamoto

June 28, 2018
Tweet

More Decks by Kōhei Yamamoto

Other Decks in Technology

Transcript

  1. ΠϯλʔϑΣʔεఆٛྫ 0QFO"1*ͷ৔߹ paths: /pets/{petId}: get: parameters: - name: petId in:

    path required: true schema: type: string responses: '200': content: application/json: schema: required: - id - name properties: id: type: integer format: int64 name: type: string (&5QFUTQFU@JE
  2. 3VCZͰεΩʔϚΛॻ͘ class Types::QueryType < Types::BaseObject field :viewer, Types::UserType, null: true

    # resolverΛॻ͍ͯͳ͍ʂ end class Types::UserType < Types::BaseObject field :email, String, null: true field :popularPosts, [Types::PostType], null: true # resolverΛॻ͍ͯͳ͍ʂ end class Types::PostType < Types::BaseObject field :title, String, null: true end
  3. HSBQIRMSVCZͰεΩʔϚΛμϯϓ FooBarSchema.to_definition # ҎԼͷจࣈྻΛऔಘ͢Δ type Query { viewer: User }

    type User { email: String popularPosts: [Post!] } type Post { title: String }
  4. (SBQI2-5PPMTͰϞοΫαʔό // express, graphql-express, body-parserͳͲΛrequire import { addMockFunctionsToSchema, makeExecutableSchema }

    = require('graphql-tools'); const schema = makeExecutableSchema({ /* μϯϓͨ͠εΩʔϚจࣈྻ */ }); const mocks = require('./mocks') addMockFunctionsToSchema({ schema, mocks }); const app = express(); app.use('/graphql', bodyParser.json(), graphqlExpress({ schema })); app.listen(3000, () => { console.log('GraphQL mock server is running!!1'); });
  5. (SBQI2-5PPMTͰϞοΫαʔό // mocks.js module.exports = { User: () => ({

    email: '[email protected]', }), Post: () => ({ title: 'The Awesome Post', }), }; ϞοΫαʔό͕ฦ͢μϛʔσʔλΛॻ͚Δ ࢦఆ͠ͳ͚Ε͹εΧϥʔܕͷ஋͸"QPMMP͕ ద౰ʹฦ͢