Skip to content

astanciu/graphql-sample

Repository files navigation

GraphQL Example

  1. Install dependencies with npm install
  2. Run the server with node server.js
  3. Open the GraphiQL UI at http://localhost:3000/graphiql

Schemas

There are other schema files that demonstrate different things:

schema.js Default schema, just returns a value. Sample query:
query {
  serverStatus
}
schema1.js Plain query with resolvers
query {
  getUsers {
    name
    email
    age
  }
}
schema2.js Query With nested objects
query {
  getUsers {
    name
    email
    age
    posts {
      id
      title
    }
  }
}
schema3.js Query with parameters
query {
  getUser(name: "alex") {
    name
    email
    age
  }
}
schema4.js Query with Mutations
mutation{
  addUser(newUser: {name: "steve", email: "[email protected]"}) {
    name
    email
    age
  }
}

Or using Query with Variable parameters:
Query:

mutation addAUser($user: UserInput){
  addUser(newUser: $user ) {
    name
    email
    age
  }
}

Parameters:

{"user":{"name": "steve", "email": "[email protected]"}}

About

Sample graphql

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published