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

Laravel With GraphQL

Laravel With GraphQL

A topic on embeding graphQL with laravel framework for a fast and sophisticated way of api build and consumption.

Sujith Kumar

February 01, 2020
Tweet

Other Decks in Technology

Transcript

  1. Hi, I’m Sujith Kumar
    I work at AlphaWebLab

    View Slide

  2. GraphQL
    GraphQL is a query language for your API, and a
    server-side runtime for executing queries by using a
    type system you define for your data

    View Slide

  3. What is GraphQL-
    ❏ Query Language ( GraphQL Schema Language )
    ❏ Type System
    type User {
    id
    name
    email
    }
    type Query {
    user {
    id
    name
    email
    }
    }
    type Mutation {
    createUser(name:“x”, email:“y”) {
    id
    name
    email
    }
    }

    View Slide

  4. ❏ Declarative Data Fetching
    ❏ Self Documenting

    View Slide

  5. GET /posts

    View Slide

  6. {
    allPosts {
    id
    title
    created_at
    user {
    id
    name
    }
    }
    }
    {
    "data": {
    "allPosts": [
    {
    "id": "1",
    "title": "Assumenda …//.",
    "created_at": "2020-01//.",
    "user": {
    "id": "1",
    "name": "Veda Ruecker"
    }
    },
    {//.},
    ]
    }
    }
    Declarative Data Fetching

    View Slide

  7. Hands-On

    View Slide

  8. Steps - Laravel & GraphQL
    ● Installation & setup
    ● Defining Type for model
    ● Query type
    ● Relationships
    ● Pagination
    ● Mutations
    ● Authentication

    View Slide

  9. Steps - Laravel & GraphQL
    ● laravel new projectName - Create new laravel project
    ● composer require nuwave/lighthouse - Install Lighthouse Package
    ● Publish default schema:
    - Run php artisan vendor:publish
    --provider="Nuwave\Lighthouse\LighthouseServiceProvider" --tag=schema
    ● Publish default config:
    ● - Run php artisan vendor:publish
    --provider="Nuwave\Lighthouse\LighthouseServiceProvider" --tag=config
    ● Install graphql-playground:
    - Run composer require mll-lab/laravel-graphql-playground

    View Slide

  10. Parameters of a resolver fn

    View Slide

  11. View Slide

  12. Github
    [https://github.com/SujithJr/laravel-graphql]
    SpeakerDeck
    [https://speakerdeck.com/sujithjr/laravel-with-graphql]

    View Slide

  13. Thank You
    @codenameJr iamsanju.jr

    View Slide