This directory contains a simple GraphQL server implementing interfaces and unions based on graphql-yoga
.
If you want to setup graphql-yoga
to consume interfaces or unions from Prisma
, you can check this post which describes how to workaround interfaces and unions in Prisma and map them back to the expected schema in graphql-yoga
.
Clone the repository:
git clone https://github.com/graphcool/graphql-yoga.git
cd graphql-yoga/examples/interface-union
Install dependencies and run the app:
yarn install # or npm install
yarn start # or npm start
Open your browser at http://localhost:4000 and start sending queries.
Interface Query:
{
character{
name
...on Human{
starships{
name
}
}
...on Droid{
primaryFunction
}
}
}
The server returns the following response:
{
"data": {
"character": {
"name": "Han Solo",
"starships": [
{
"name": "Millennium Falcon"
}
]
}
}
}
Union Query:
{
humanOrDroid{
...on Human{
name
starships{
name
}
}
...on Droid{
name
primaryFunction
}
}
}
The server returns the following response:
{
"data": {
"humanOrDroid": {
"name": "R2-D2",
"primaryFunction": "Astromech"
}
}
}