Skip to content

📋 Unified GraphQL examples written in Go, Node.js, PHP.

License

Notifications You must be signed in to change notification settings

WindomZ/graphql-examples

Repository files navigation

graphql-examples

Unified GraphQL examples written in Go, Node.js, PHP.

Build Status Go Report Card Greenkeeper badge Dependency styled with prettier License

Purpose

  • Unified GraphQL example template.
  • Multiple languages: Go, Node.js, PHP.
  • Easy to learn primary GraphQL.
  • Test compatibility.
  • HTTP services.

Install

Go

go get github.com/WindomZ/graphql-examples/...

Node.js

npm install
# or
yarn

PHP

composer install

Usage

Single

Each under the go, nodejs, php directory paths.

Integrated

If you have Go(go get), PHP(composer), Node.js(npm/yarn) installed.

You can run and select service:

./run.sh

Run the test with all above languages:

./test.sh

Template

Define a schema that is the basis for all queries:

// add a User type
type User {
  id: String!
  name: String
}

// define a schema
type Query {
  hello(message: String): String
  bye: String
  user(id: String!): User
}
type Mutation {
  sum(x: Int, y: Int): Int
}

The example queries on the above schema would be:

Query hello:

query Query {
  hello(message: "world")
}

Query bye:

// test root values
query Query {
  bye
}

Query user:

// test numbers and some symbols
query Query {
  user(id:"1") {
    name
  }
}
// test English
query Query {
  user(id:"id") {
    name
  }
}
// test Chinese
query Query {
  user(id:"编号") {
    name
  }
}

Query sum:

mutation Calc {
  sum(x: 1, y: 2)
}

Related

Contributing

Welcome to pull requests, report bugs, suggest ideas and discuss graphql-examples on issues page.

If you like it then you can put a ⭐ on it.

Roadmap

  • Support Golang.
  • Support Node.js.
  • Support PHP.
  • Support Java.
  • Hello & Bye example template.
  • Calc(sum) example template.
  • User example template.
  • Star Wars example template.
  • HTTP services.
  • HTTPS services.
  • RPC services.

License

MIT