Skip to content

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

Notifications You must be signed in to change notification settings

shahabqamar/graphql-php-sqlite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-php-sqlite

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

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages