Developer Tools
Tools and methods for working with Common Ground's GraphQL APIs. Choose the approach that fits your development environment.
GraphQL Clients
GraphQL clients handle caching, error management, and type safety:
- Apollo Client - Popular client for JavaScript/React applications
- Relay - Facebook's GraphQL client framework, optimized for performance
- urql - Lightweight and highly customizable GraphQL client
- graphql-request - Minimal GraphQL client for Node.js and browsers
Apollo Client Example
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const client = new ApolloClient({
uri: 'https://api.common-ground.io/graphql/graphql',
cache: new InMemoryCache(),
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'CommonGround-Origin': 'www.my-store.com'
},
});
const GET_ITEMS = gql`
query GetItems {
items(pagination: { page: 1, limit: 10 }) {
items {
_id
title
price
}
}
}
`;
const { data } = await client.query({ query: GET_ITEMS });
HTTP Libraries
Use standard HTTP libraries to make GraphQL requests. GraphQL operations use POST requests with a JSON-encoded body.
curl
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "CommonGround-Origin: www.my-store.com" \
-d '{"query": "query { items { items { _id title } } }"}' \
https://api.common-ground.io/graphql/graphql
JavaScript (fetch)
const response = await fetch('https://api.common-ground.io/graphql/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN',
'CommonGround-Origin': 'www.my-store.com'
},
body: JSON.stringify({
query: `
query GetItems {
items(pagination: { page: 1, limit: 10 }) {
items {
_id
title
}
}
}
`
})
});
const data = await response.json();
Python (requests)
import requests
response = requests.post(
'https://api.common-ground.io/graphql/graphql',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN',
'CommonGround-Origin': 'www.my-store.com'
},
json={
'query': '''
query GetItems {
items(pagination: { page: 1, limit: 10 }) {
items {
_id
title
}
}
}
'''
}
)
data = response.json()
GraphQL IDEs
Interactive environments for exploring schemas, writing queries, and testing operations:
- GraphiQL - In-browser IDE for exploring GraphQL
- GraphQL Playground - Feature-rich IDE with query history
- Insomnia - REST and GraphQL client with autocomplete
- Postman - API client with GraphQL support
- Altair - Desktop app, browser extension, or web app
Load the downloadable schema files into these IDEs for autocomplete and validation.
Schema Tools
Downloadable schema files can be used with:
- GraphQL Code Generator - Generate type-safe code from schemas
- GraphQL Inspector - Validate and compare schemas
- IDE plugins - Autocomplete and validation in your editor
Download schema files from:
Getting Started
Choose your path:
I want to use Apollo Client
- Install:
npm install @apollo/client - Configure client with your API endpoint and authentication headers
- Write queries using
gqltemplate literals - Execute queries with
client.query()orclient.mutate()
I want to use fetch/HTTP libraries
- Set up POST requests to the GraphQL endpoint
- Include
Content-Type: application/jsonheader - Include authentication headers (
Authorization,CommonGround-Origin) - Send JSON body with
queryand optionalvariablesfields - Parse JSON response and check for
errorsarray
I want to use a GraphQL IDE
- Download the schema file for your API
- Load schema into your IDE
- Configure authentication headers
- Write and test queries interactively
Further Reading
- Starting - Learn fundamental GraphQL concepts
- Working with Queries - Learn how to write queries
- Working with Mutations - Learn how to write mutations
- Paginating - Understand how to paginate results
- Filtering Data - Learn how to filter and sort
- Handling Errors - Handle errors and responses
- Admin API Overview - Admin API documentation and authentication
- Client API Overview - Client API documentation and authentication