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

graphql in laravel(lighthouse-php)

qazz92
February 21, 2020

graphql in laravel(lighthouse-php)

Graphql in laravel

by Comento

qazz92

February 21, 2020
Tweet

Other Decks in Programming

Transcript

  1. RESTful API Method Route Action GET /post Ӗ ݾ۾ ੍ӝ

    GET /post/:id ౠ੿ Ӗ ੍ӝ POST /post Ӗ ੷੢ PUT/PATCH /post/:id Ӗ ੷੢ DELETE /post/:id Ӗ ࢏ઁ
  2. RESTful API ݽ߄ੌীࢲ ׮ܲ Ѧ ୶о੸ਵ۽ ࠁৈ઻ঠ ೠ׮Ѣա, ࡐঠ ೠ׮ݶ?

    => /postAndCommentsAndLikes/:id?platform=mobile э਷ api ܳ ׮ܲ Ҕীࢲ ੤ࢎਊ ೧ঠ ೞחؘ ӂೠ੉ ୶оغযঠ ೠ׮ݶ? э਷ api ܳ ׮ܲ Ҕীࢲ ੤ࢎਊ ೧ঠ ҙ҅о ୶о غঠ ೠ׮ݶ? …
  3. RESTful API front-end ‘஬೐ apiীࢲ ݭష ੿ࠁө૑ ઱ࣁਃ.’ back-end GET

    /edu/camp/:id?mentor=1 ӝദ੗ ‘ই! ݽ߄ੌীࢲח ஬೐ ੢ࣗܳ ࡐ઱ࣁਃ’ front-end back-end ‘….’ front-end ௏٘ ࣻ੿ back-end GET /edu/camp/:id?mentor=1&location=0 front-end ௏٘ ࣻ੿ back-end ޙࢲ ١ সؘ੉౟ back-end front-end ழޭפா੉࣌ ࠺ਊ ֫਺
  4. front-end ‘஬೐ apiীࢲ ݭష ੿ࠁ?’ front-end { camp(id: 214) {

    mentor { name company } title back_img } } front-end ௏٘ ࣻ੿ ࢲߡীࢲח ௪ܻ੄ झಖ݅ ઓ੤! ৻ࠗ੄ झಖ੉ա ޙࢲী ੄ઓ X ழޭפா੉࣌ ࠺ਊ хࣗ GraphQL
  5. GraphQL - Basic Query Mutation read data write data Type

    model type user { id: ID! email: String! pw: String! } query { user(id: 1) { id email } } mutation { creaetUser ( email: "[email protected]" pw: “test” ) { id } }
  6. GraphQL Lighthouse-php ৵? ࠁా਷ apollo! but ࢲߡ ҙܻ ӈଳ ੢੼਷?

    eloquent ORM! ױ੼਷? ࠂ੟ೠ ௪ܻܳ ࢎਊೞ۰ݶ ѾҴ schema ੉৻੄ ੘স੉ ೙ਃ
  7. GraphQL Lighthouse-php with EloquentORM Example 1. Type ੿੄ type User

    { id: ID! email: String! type: Int! } Eloquent ORM ੄ ݽ؛җ ڙэ੉ ੘ࢿ
  8. GraphQL Lighthouse-php with EloquentORM 2. Read type Query { user(id:

    ID! @eq) : User! @find } 2-1. ױੌ ઑഥ => select * from user where id = :id limit 1 Example
  9. GraphQL Lighthouse-php with EloquentORM type Query { user(id: ID! @eq)

    : User! @find } ઑѤਸ ೲਊೡ ஸۢҗ ఋੑ૑੿ where ‘=’ ߈ജ ఋੑ ->first()
  10. GraphQL Lighthouse-php with EloquentORM 2. Read type Query { user(type:

    Int! @eq) : [User!]! @all } 2-2. ܻझ౟ ઑഥ => select * from user where type = :type Example
  11. GraphQL Lighthouse-php with EloquentORM ߈ജ ఋੑ ૑੿ ( ߓৌ )

    type Query { user(type: Int! @eq) : [User!]! @all } ->get() ઑѤਸ ೲਊೡ ஸۢҗ ఋੑ૑੿ where ‘=’
  12. GraphQL Lighthouse-php with EloquentORM 2. Read type Query { user(type:

    Int! @eq) : [User!]! @pagination } 2-2. ܻझ౟ ઑഥ (ಕ੉૑֎੉࣌) => select * from user where type = :type offset :offset limit :limit Example
  13. GraphQL Lighthouse-php with EloquentORM 3. Middleware type Query { user(type:

    Int! @eq) : [User!]! @pagination @middleware(checks: ["auth:api"]) } Example
  14. GraphQL Lighthouse-php with EloquentORM 4. Muatation type Muatation { createUser(

    email: String! pw: String! ) : User! @create } @create, @update, @delete, @upsert(updateOrCreate) Example
  15. GraphQL Lighthouse-php with EloquentORM 5. Eloquent Relationships Example type Post

    { id: ID! email: String! type: Int! Author: User! @belongsTo(relation: “user”) } class User extends Model { …… public function user() { return $this->belongsTo(User::class) } } => Model ੄ ҙ҅৬ ੉ܴਸ ڙэ੉ ੸যષ @hasOne, @hasMany, @belongsToMany, @belongsTo
  16. GraphQL Lighthouse-php with EloquentORM query { post(no : 1) {

    no title user { email } } } { "data": { "post": { "no": “1", "title": “test", "user": { “email": "5" } } } } =>
  17. GraphQL Lighthouse-php with EloquentORM 6. Event Example type Muatation {

    createUser( email: String! pw: String! ) : User! @create @event(dispatch: "App\\Events\ \CreateUserEvent") } Event direction ਸ ాೞৈ query / mutation ੉റ੄ ݫੌ ੹࣠ ١ ৈ۞ ೯زٜਸ ೡ ࣻ ੓ѱ ࢸ੿ ೡ ࣻ ੓਺ laravel events class
  18. GraphQL नӏ दझమী ੸ਊ Ѿҗ ਗې flow controller / service

    / repository => route ١۾ => response ҳઑ ҕਬ(ޙࢲ) => ೖ٘ߔ => ޖೠ ߈ࠂ ՙীীীীু!