Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/manuelgeek/laravel-graphql

A laravel graphQL API application sample
https://github.com/manuelgeek/laravel-graphql

api graphql laravel

Last synced: about 5 hours ago
JSON representation

A laravel graphQL API application sample

Awesome Lists containing this project

README

        

![badge](https://github.com/manuelgeek/laravel-graphql/workflows/Laravel/badge.svg)
[![StyleCI](https://github.styleci.io/repos/256302652/shield?branch=master)](https://github.styleci.io/repos/256302652)

## About Laravel GraphQL

This is a sample Laravel Project to illustrate API creation using GraphQL using [grapgql-laravel](https://github.com/rebing/graphql-laravel) package

## Set up

Fork and Clone the project then;

```bash
composer install

cp .env.example .env

php artisan key:generate

php artisan migrate

php artisan serve

```

## Features
* Register
* Login
* Update Avatar
* CRUD
* Pagination

## Sample Urls

### 1. Create user
#### Request
http://localhost:8000/graphql/auth
```
mutation {
signUp(
name: "tester"
email:"[email protected]"
password:"123"
) {
id,
email,
name,
api_token
}
}

```

#### Response
```json
{
"data": {
"signUp": {
"id": 1,
"email": "[email protected]",
"name": "tester",
"api_token": "09SBifku0BCSNS7VBFNqQg0goDYqCX43tL4pNtl7lJPmVOJOjDdjD42mnmuOLBybwW7DHZmrnVTey0p8nH4EWGGa7oRKErnZMm9c"
}
}
}
```

### 2. Login

http://localhost:8000/graphql/auth
#### Request
```
mutation {
logIn(
email:"[email protected]"
password:"123"
) {
id,
email,
name,
api_token
}
}
```

#### Response
```json
{
"data": {
"logIn": {
"id": 1,
"email": "[email protected]",
"name": "tester",
"api_token": "09SBifku0BCSNS7VBFNqQg0goDYqCX43tL4pNtl7lJPmVOJOjDdjD42mnmuOLBybwW7DHZmrnVTey0p8nH4EWGGa7oRKErnZMm9c"
}
}
}
```

### 3. Get Bits

http://localhost:8000/graphql

#### Request
```
mutation {
newBit (snippet: "") {
id
user {
id
name
}
snippet
created_at
updated_at
}
}
```
#### Response
```json
{
"data": {
"newBit": {
"id": 2,
"user": {
"id": 1,
"name": "tester"
},
"snippet": "",
"created_at": "2020-04-16 18:27:07",
"updated_at": "2020-04-16 18:27:07"
}
}
}

```

### 4. Update Avatar
http://localhost:8000/graphql
#### Request

```
mutation($file: Upload!)
{ UpdateUserProfilePhoto(profilePicture: $file)
{
id,
name,
avatar,
email,
api_token
}
}
```

## Resources

The sample project is created from serries of lessons from;
1. [Auth0 Blog](https://auth0.com/blog/developing-and-securing-graphql-apis-with-laravel/)

2. [Pusher Blog](https://blog.pusher.com/building-apis-laravel-graphql/)

## About Me
[Magak](https://magak.me)
## License

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)](#)

[![Open Source Love](https://badges.frapsoft.com/os/v2/open-source-200x33.png?v=103)](#)

Happy coding, Star then Fork 😊💪💯