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

GraphQLを活用するツールやライブラリ / graphql-libraries

GraphQLを活用するツールやライブラリ / graphql-libraries

howyi

July 12, 2019
Tweet

More Decks by howyi

Other Decks in Programming

Transcript

  1. Insomnia ▸ GraphQLΛ࣮ߦ͢ΔΞϓϦ(2) ▸ POSTMANͷGraphQL൛Έ͍ͨ ͳ΋ͷ ▸ POSTMAN΋ࠓGraphQLରԠ ͕βஈ֊ ▸

    GraphQLͷIntrospectionʹରԠ ͓ͯ͠Γɺೖྗʹ༧ଌ͕ೖΔͨ Ίૢ࡞͠΍͍͢
  2. LightHouse ▸ LaravelϓϥάΠϯ ▸ ΈΜͳେ޷͖PHP ▸ GraphQLͷType͕EloquentͷϞσϧͱͳΔ ▸ @hasMany ΍

    @belongToͷEloquentͷRelationShipΛ FieldͷDirectiveͱͯ͠࢖ ༻Ͱ͖Δ
  3. ίʔυ LightHouse type User { id: ID! name: String! email:

    String posts: [Post!]! @hasMany } type Post { title: String! content: String! author: User @belongsTo } type Query { me: User @auth posts: [Post!]! @paginate } type Mutation { createPost( title: String @rules(apply: ["required", "min:2"]) content: String @rules(apply: ["required", "min:12"]) ): Post @create } ςʔϒϧʹͳΔ
  4. ೝূػೳ LightHouse type Query { me: User @auth } LaravelͷAPI

    Authenticationͱ࿈ܞ͠ɺࣗ෼ͷUserϞσϧΛฦ͢ίʔ υɺAPIΛࣗಈੜ੒͢Δ
  5. ಠࣗDirectiveͷ࡞੒ LightHouse <?php namespace App\GraphQL\Directives; use Closure; use GraphQL\Type\Definition\ResolveInfo; use

    Nuwave\Lighthouse\Schema\Values\FieldValue; use Nuwave\Lighthouse\Support\Contracts\Directive; use Nuwave\Lighthouse\Support\Contracts\FieldMiddleware; use Nuwave\Lighthouse\Support\Contracts\GraphQLContext; class UpperCaseDirective implements Directive, FieldMiddleware { public function name(): string { return 'upperCase'; } public function handleField(FieldValue $fieldValue, Closure $next): FieldValue { // FieldʹDirectiveΛهࡌͨ͠ͱ͖ͷڍಈ } } LightHouseͷDirective ʹՃ͑ͯPHPͰ ಠࣗDirectiveΛ࡞੒Ͱ͖Δ ֦ுੑ͕ແݶ