GraphQL and Schema-First Development

GraphQL and Schema-First Development

GraphQL NightでのLT発表資料です

1604058c93731a1f795ce62d37d19fd5?s=128

Kōhei Yamamoto

June 28, 2018
Tweet

Transcript

  1. 3.
  2. 7.

    ΠϯλʔϑΣʔεఆٛྫ 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
  3. 13.

    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
  4. 14.

    HSBQIRMSVCZͰεΩʔϚΛμϯϓ FooBarSchema.to_definition # ҎԼͷจࣈྻΛऔಘ͢Δ type Query { viewer: User }

    type User { email: String popularPosts: [Post!] } type Post { title: String }
  5. 16.

    (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'); });
  6. 17.

    (SBQI2-5PPMTͰϞοΫαʔό // mocks.js module.exports = { User: () => ({

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