Git Product home page Git Product logo

graphql-demo's Introduction

GraphQL with Laravel & View

Intro

Setup

  • Install Laravel
$ laravel new graphql-demo
$ php artisan --version
Laravel Framework 8.78.0
  • Add a post model with related components
$ php artisan make:model Post -a
Model created successfully.
Factory created successfully.
Created Migration: 2022_01_05_000252_create_posts_table
Seeder created successfully.
Request created successfully.
Request created successfully.
Controller created successfully.
Policy created successfully.
  • Add model relationships
  • Add model seeder

GraphQL support

# Install via composer
$ composer require nuwave/lighthouse
Publishing complete.

# Publish the default schema
$ php artisan vendor:publish --tag=lighthouse-schema
Publishing complete.

# Publish the default config
$ php artisan vendor:publish --tag=lighthouse-config
Publishing complete.

# Install devtools
$ composer require mll-lab/laravel-graphql-playground
Publishing complete.

# IDE Support helpers
$ php artisan lighthouse:ide-helper
  • Update graphql/schema.graphql to include Posts and other relationships
type Query {
    users: [User!]! @paginate(defaultCount: 10)
    user(id: ID @eq): User @find
+    posts: [Post!]! @all
+    post(id: ID @eq): Post @find
}

type User {
    id: ID!
    name: String!
    email: String!
+    posts: [Post!]! @hasMany
    created_at: DateTime!
    updated_at: DateTime!
}

+ type Post {
+     id: ID!
+     title: String!
+     body: String!
+     user: User! @belongsTo
+     created_at: DateTime!
+     updated_at: DateTime!
+ }

graphql-demo's People

Contributors

tyler36 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.