LogoLogo
WebsiteLoginStatus
API Reference
API Reference
  • Introduction
  • Introduction to GraphQL
    • What is GraphQL?
      • GraphQL Schema
      • Example Using GraphQL
    • Authentication
    • Queries
      • Example Query
    • Mutations
      • Example Mutation
    • Variables
    • Fields
  • Develop With inabit API
    • Getting Started
      • Authentication
      • inabit Postman Collection
    • Organizations
      • Organization Info
      • Organization ID
      • Organization Users
      • Organization Contacts
      • Organization Transactions
    • Wallets
      • Wallets Info
      • Create inabit Wallet
      • Edit Wallet Name
      • Generate Deposit Address
      • Fetch Deposit Address
      • Save Address to Whitelist
      • Archive / Unarchive Wallet
      • Disconnect Exchange Wallet
    • Contacts
      • Contact Info
      • Create New Contact
      • Update Contact
    • Transactions
      • Transaction Info
      • Create Transfer Request
      • Create Off Ramp Request
      • Create On Ramp Request
      • Create Exchange Swap
      • Create inabit Wallet Swap
      • Edit Transaction Note
    • Utilities
      • Fetch Financial Asset
      • Fetch Blockchains
  • Remote Approver App
    • Setup and Configuration
    • API Wallets Generation
    • Automate Signing Transactions
    • Webhooks
      • Notification Types
  • WHAT WE SUPPORT
    • Assets & Tokens
    • Blockchains
    • Exchanges
      • Binance
      • Kucoin
      • Kraken
  • Changelog
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Introduction to GraphQL
  2. What is GraphQL?

Example Using GraphQL

Toy Store API with GraphQL: A Hands-on Example

This example showcases a basic GraphQL API for a toy store, demonstrating the schema, queries, and mutations.

Schema:

type Toy {
  id: ID!
  name: String!
  price: Float!
  category: String!
  inStock: Boolean!
}

type Query {
  toys(category: String): [Toy!]!
  toy(id: ID!): Toy
}

type Mutation {
  createToy(name: String!, price: Float!, category: String!): Toy!
}

Explanation:

  • Types:

    • Toy: Represents a toy object with properties like id, name, price, category, and inStock.

    • Query: Defines available data retrieval operations.

    • Mutation: Defines data manipulation operations (optional, not all APIs have mutations).

  • Query:

    • toys(category: String): Retrieves a list of toys based on an optional category filter.

    • toy(id: ID!): Fetches a specific toy by its ID.

  • Mutation:

    • createToy(name: String!, price: Float!, category: String!): Creates a new toy with provided details.

Query Example (Get all toys):

query {
  toys
}

Response:

{
  "data": {
    "toys": [
      {
        "id": "1",
        "name": "Stuffed Bear",
        "price": 19.99,
        "category": "Plushies",
        "inStock": true
      },
      {
        "id": "2",
        "name": "Remote Control Car",
        "price": 49.99,
        "category": "Vehicles",
        "inStock": false
      }
    ]
  }
}

Query Example (Get a toy by ID):

query getToy($id: ID!) {
  toy(id: $id) {
    id
    name
    price
  }
}

Variables:

{
  "id": "1"
}

Response:

{
  "data": {
    "toy": {
      "id": "1",
      "name": "Stuffed Bear",
      "price": 19.99
    }
  }
}

Mutation Example (Create a new toy):

mutation createToy($name: String!, $price: Float!, $category: String!) {
  createToy(name: $name, price: $price, category: $category) {
    id
    name
    price
    category
  }
}

Variables:

{
  "name": "Building Blocks",
  "price": 24.99,
  "category": "Construction"
}

Response:

{
  "data": {
    "createToy": {
      "id": "3",  // Generated by the server
      "name": "Building Blocks",
      "price": 24.99,
      "category": "Construction"
    }
  }
}

This example demonstrates the fundamental concepts of using a GraphQL API. By understanding the schema, you can craft queries to retrieve specific data and potentially use mutations to interact with the data (if supported).

PreviousGraphQL SchemaNextAuthentication

Was this helpful?