Skip to content

samnight/graphql-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

interface and unions

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.

Get started

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

Testing

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"
    }
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published