Skip to content

Commit

Permalink
[IMP] add new schema with documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Elise17 committed Mar 14, 2024
1 parent 4c35341 commit fe2cadc
Showing 1 changed file with 229 additions and 55 deletions.
284 changes: 229 additions & 55 deletions experiments/graphql-rest/POC-Graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,52 +69,58 @@ The database gdb should be available on the interface, port 5433 protocol HTTP -

### Graphql schema
``` bash
schema {
query: Query
mutation: Mutation
}

type AddBook {
book: BookObject
}

type AuthorConnection {
pageInfo: PageInfo!
edges: [AuthorEdge]!
}

type AuthorEdge {
node: AuthorObject
cursor: String!
}

"""Documentation about user informations."""
type AuthorObject implements Node {
"""The ID of the object"""
id: ID!
username: String!
email: String!
books(before: String, after: String, first: Int, last: Int): BookObjectConnection
}

enum AuthorObjectSortEnum {
ID_ASC
ID_DESC
USERNAME_ASC
USERNAME_DESC
EMAIL_ASC
EMAIL_DESC
"""An object with an ID"""
interface Node {
"""The ID of the object"""
id: ID!
}

type BookConnection {
type BookObjectConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!
edges: [BookEdge]!

"""Contains the nodes in this connection."""
edges: [BookObjectEdge]!
}

type BookEdge {
"""
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
"""
type PageInfo {
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!

"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!

"""When paginating backwards, the cursor to continue."""
startCursor: String

"""When paginating forwards, the cursor to continue."""
endCursor: String
}

"""A Relay edge containing a `BookObject` and its cursor."""
type BookObjectEdge {
"""The item at the end of the edge"""
node: BookObject

"""A cursor for use in pagination"""
cursor: String!
}

"""Documentation about different authors."""
type BookObject implements Node {
"""The ID of the object"""
id: ID!
title: String!
description: String!
Expand All @@ -123,16 +129,62 @@ type BookObject implements Node {
author: AuthorObject
}

type BookObjectConnection {
"""Documentation about different movies."""
type MovieObject implements Node {
"""The ID of the object"""
id: ID!
title: String!
description: String!
authorId: Int
}

"""Query documentation"""
type Query {
node(
"""The ID of the object"""
id: ID!
): Node

"""author documentation"""
author(username: String): [AuthorObject]

"""book documentation"""
book(title: String): [BookObject]

"""movie documentation"""
movie(title: String): [MovieObject]

"""book all documentation"""
bookAll: [BookObject]

"""movie all documentation"""
movieAll: [MovieObject]

"""author all documentation"""
authorAll: [AuthorObject]
allBooks(sort: [BookObjectSortEnum] = [ID_ASC], filter: BookObjectFilter, before: String, after: String, first: Int, last: Int): BookConnection
allAuthors(sort: [AuthorObjectSortEnum] = [ID_ASC], filter: AuthorObjectFilter, before: String, after: String, first: Int, last: Int): AuthorConnection
allMovies(sort: [MovieObjectSortEnum] = [ID_ASC], filter: MovieObjectFilter, before: String, after: String, first: Int, last: Int): MovieConnection
}

type BookConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!
edges: [BookObjectEdge]!

"""Contains the nodes in this connection."""
edges: [BookEdge]!
}

type BookObjectEdge {
"""A Relay edge containing a `Book` and its cursor."""
type BookEdge {
"""The item at the end of the edge"""
node: BookObject

"""A cursor for use in pagination"""
cursor: String!
}

"""An enumeration."""
enum BookObjectSortEnum {
ID_ASC
ID_DESC
Expand All @@ -146,23 +198,104 @@ enum BookObjectSortEnum {
AUTHOR_ID_DESC
}

input BookObjectFilter {
id: IdFilter
title: StringFilter
description: StringFilter
year: IntFilter
authorId: IntFilter
author: AuthorObjectFilter
and: [BookObjectFilter]
or: [BookObjectFilter]
}

input IdFilter {
eq: ID
in: [ID]
nEq: ID
notIn: [ID]
}

input StringFilter {
eq: String
ilike: String
in: [String]
like: String
nEq: String
notIn: [String]
notlike: String
}

input IntFilter {
eq: Int
gt: Int
gte: Int
in: [Int]
lt: Int
lte: Int
nEq: Int
notIn: [Int]
}

input AuthorObjectFilter {
id: IdFilter
username: StringFilter
email: StringFilter
books: BookObjectRelationshipFilter
and: [AuthorObjectFilter]
or: [AuthorObjectFilter]
}

input BookObjectRelationshipFilter {
containsExactly: [BookObjectFilter]
contains: [BookObjectFilter]
}

type AuthorConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!

"""Contains the nodes in this connection."""
edges: [AuthorEdge]!
}

"""A Relay edge containing a `Author` and its cursor."""
type AuthorEdge {
"""The item at the end of the edge"""
node: AuthorObject

"""A cursor for use in pagination"""
cursor: String!
}

"""An enumeration."""
enum AuthorObjectSortEnum {
ID_ASC
ID_DESC
USERNAME_ASC
USERNAME_DESC
EMAIL_ASC
EMAIL_DESC
}

type MovieConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!

"""Contains the nodes in this connection."""
edges: [MovieEdge]!
}

"""A Relay edge containing a `Movie` and its cursor."""
type MovieEdge {
"""The item at the end of the edge"""
node: MovieObject
cursor: String!
}

type MovieObject implements Node {
id: ID!
title: String!
description: String!
authorId: Int
"""A cursor for use in pagination"""
cursor: String!
}

"""An enumeration."""
enum MovieObjectSortEnum {
ID_ASC
ID_DESC
Expand All @@ -174,30 +307,34 @@ enum MovieObjectSortEnum {
AUTHOR_ID_DESC
}

input MovieObjectFilter {
id: IdFilter
title: StringFilter
description: StringFilter
authorId: IntFilter
and: [MovieObjectFilter]
or: [MovieObjectFilter]
}

"""Mutation documentation"""
type Mutation {
"""Mutation Addbook """
addBook(description: String!, title: String!, username: String!, year: Int!): AddBook
}

interface Node {
id: ID!
"""Mutation Updatebook """
updateBook(authorId: Int, description: String!, title: String!, year: Int!): UpdateBook
}

type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
"""Mutation Addbook """
type AddBook {
book: BookObject
}

type Query {
node(id: ID!): Node
author(username: String): [AuthorObject]
book(title: String): [BookObject]
movie(title: String): [MovieObject]
allBooks(sort: [BookObjectSortEnum] = [ID_ASC], before: String, after: String, first: Int, last: Int): BookConnection
allAuthors(sort: [AuthorObjectSortEnum] = [ID_ASC], before: String, after: String, first: Int, last: Int): AuthorConnection
allMovies(sort: [MovieObjectSortEnum] = [ID_ASC], before: String, after: String, first: Int, last: Int): MovieConnection
"""Mutation Updatebook """
type UpdateBook {
book: BookObject
}

```

### Run app.py
Expand Down Expand Up @@ -259,6 +396,15 @@ Other example request via GraphiQL
}
```

``` bash
# Another way to write the query allmovie
{
movieAll {
description
title
}
}
```
Example mutation via GraphiQL
``` bash
# Make a GraphQl mutation
Expand Down Expand Up @@ -295,6 +441,34 @@ Answer via GraphiQL
}
}
```
Example mutation via GraphiQL
``` bash
mutation {
updateBook(
title:"Pride and prejudice",
description:"POC GraphQL 2",
year:2018){
book{
title
description
}
}
}
```
Answer via GraphiQL
``` bash
{
"data": {
"updateBook": {
"book": {
"title": "Pride and prejudice",
"description": "POC GraphQL 2"
}
}
}
}

```
Documentation GraphQL
``` bash
#Install dociql
Expand Down

0 comments on commit fe2cadc

Please sign in to comment.