Code Monkey home page Code Monkey logo

graphql-eloquent-standalone's Introduction

graphql-php-sqlite

A basic graphql server using the graphql-php package that works with a sqlite database.

Browsing API

The most convenient way to browse GraphQL API is by using GraphiQL But setting it up from scratch may be inconvenient. An easy alternative is to use one of the existing Google Chrome extensions:

Set http://localhost:8080?debug=1 as your GraphQL endpoint/server in one of these extensions and try clicking "Docs" button (usually in the top-right corner) to browse auto-generated documentation.

Setup

Instructions assume your are running MAMP (or alike) but MAMP is certainly not required. Feel free to use a PHP environment of your choice.

  1. Clone the repo in htdocs
  2. Make sure you have composer installed. Navigate to the project folder and run composer install
  3. Fire up MAMP (or your favourite PHP environment) and open API url in the browser. It should look something like: http://localhost:<port>/graphql-php-sqlite/server/api.php and throw a JSON error message:
{
  errors: [
    {
      message: "GraphQL Request must include at least one of those two parameters: "query" or "queryId"",
      category: "request"
    }
  ]
} 

That's ok, it is expected behaviour.

  1. Now test if the sqlite DB connection is working. Navigate to: http://localhost:<port>/graphql-php-sqlite/db/db-test.php If you see a response like the following:
Array
(
    [0] => Array
        (
            [id] => 1
            [firstName] => Shahab
            [lastName] => Qamar
            [email] => [email protected]
        )

    [1] => Array
        (
            [id] => 2
            [firstName] => Andrew
            [lastName] => Byrne
            [email] => [email protected]
        )

    [2] => Array
        (
            [id] => 3
            [firstName] => Scott
            [lastName] => Hall
            [email] => [email protected]
        )

)

congratulations, you are all set. If you are getting a 500 internal server error, check if your PHP installation has sqlite enabled.

  1. Install and launch the ChromeiQL extension for Chrome https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij which is an implementation of GraphiQL client.

  2. In the ChromeiQL UI, set http://localhost:<port>/graphql-php-sqlite/server/api.php as your endpoint. At the top right, click to expand the Docs section. You should see the following root types:

query: Query
mutation: mutation

Awesome! thats all to it. Lets run an example query. Type the following query and hit play:

{
  user(id:1) {
    firstName
    email
  }
}

You should get something like:

{
  "data": {
    "user": {
      "firstName": "Shahab",
      "email": "[email protected]"
    }
  }
}

Useful links

graphql-eloquent-standalone's People

Contributors

limweb avatar

Watchers

James Cloos avatar  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.