Developer Tools
Tools and methods for working with Common Ground's GraphQL APIs. Choose the approach that fits your development environment.
Endpoints and authentication
| API | Endpoint | Auth |
|---|---|---|
| Admin API | https://api-admin.common-ground.io/graphql | Authorization: Bearer sk-… only |
| Client API | https://your-shop-name.common-ground.io/graphql | Store from the subdomain URL; Authorization: Bearer <jwt> for authenticated operations |
See Admin API Overview and Client API Overview for full details. Examples below use the Admin API.
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-admin.common-ground.io/graphql',
cache: new InMemoryCache(),
headers: {
'Authorization': 'Bearer sk-...'
},
});
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 sk-..." \
-d '{"query": "query { items { items { _id title } } }"}' \
https://api-admin.common-ground.io/graphql
JavaScript (fetch)
const response = await fetch('https://api-admin.common-ground.io/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-...'
},
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-admin.common-ground.io/graphql',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-...'
},
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 for your API (
Authorizationfor Admin secret keys or Client JWTs as needed) - 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