- java 11
Use Altair plugin
http://localhost:8085/graphql
Query operation
query{
findAll{
id
url
description
}
}
Mutation operation
mutation{
saveComment(id: 5, title: "FAQ ", createdAt: "2020/11/21 13:22:41")
}
-
query interface
query{ findVehicle{ __typename, ... on Car { id enginePower } ... on Van { id enginePower isOffRoad } } } -
Query output
{ "data": { "findVehicle": [ { "__typename": "Van", "id": "Van100", "enginePower": "HP_3000", "isOffRoad": true }, { "__typename": "Car", "id": "Car 120", "enginePower": "HP_1500" } ] } } -
Mutation on interface
mutation{ saveCar(id: "Preus 2008", enginePower: HP_1500) }
-
query operation
query{ books{ edges{ cursor node{ id title author } }, pageInfo{ hasPreviousPage hasNextPage startCursor endCursor } } } -
query output
{ "data": { "books": { "edges": [ { "cursor": "c2ltcGxlLWN1cnNvcjA=", "node": { "id": "1245", "title": "Jane Eyre", "author": "Charlot Bronte" } }, { "cursor": "c2ltcGxlLWN1cnNvcjE=", "node": { "id": "1285", "title": "Village By the Sea", "author": "Anita Desai" } }, { "cursor": "c2ltcGxlLWN1cnNvcjI=", "node": { "id": "1259", "title": "Mother", "author": "Maximum Ghorky" } }, { "cursor": "c2ltcGxlLWN1cnNvcjM=", "node": { "id": "1273", "title": "Anne Frank huis", "author": "Anne Frank" } } ], "pageInfo": { "hasPreviousPage": false, "hasNextPage": false, "startCursor": "c2ltcGxlLWN1cnNvcjA=", "endCursor": "c2ltcGxlLWN1cnNvcjM=" } } } } -
paginated query operation
query($first: Int, $after: String){ books(first: $first, after: $after){ edges{ cursor node{ id title author } }, pageInfo{ hasPreviousPage hasNextPage startCursor endCursor } } } -
variables
{ "first": 3, "after": "c2ltcGxlLWN1cnNvcjA=" } a cursor value should be placed after the "after"
-
use
http://localhost:8085/graphiqlin your browser to test subscriptionssubscription { comments { id title createdAt } }
Ref :
https://graphql.org/learn/schema/
https://www.howtographql.com/graphql-java/9-filtering/
https://developer.okta.com/blog/2020/01/31/java-graphql
polymophic : https://medium.com/better-programming/using-graphql-with-spring-boot-interfaces-and-unions-a76f62d62867
client Library : https://ktor.io/docs/clients-index.html