# Example GraphQL Queries and Mutations
This document contains example GraphQL operations you can use with the ADL system.
## Queries
### Get All ADL Entries
```graphql
query GetAllEntries {
adlEntries {
id
created
lastEdited
author
title
decision
factSheets
status
}
}
```
### Get Single ADL Entry
```graphql
query GetEntry($id: ID!) {
adlEntry(id: $id) {
id
created
lastEdited
author
title
decision
factSheets
status
}
}
```
**Variables:**
```json
{
"id": "your-entry-id-here"
}
```
## Mutations
### Create New ADL Entry
```graphql
mutation CreateEntry($input: CreateADLEntryInput!) {
createADLEntry(input: $input) {
id
created
lastEdited
author
title
decision
factSheets
status
}
}
```
**Variables:**
```json
{
"input": {
"author": "John Doe",
"title": "Adopt Microservices Architecture",
"decision": "After careful consideration, we have decided to migrate our monolithic application to a microservices architecture. This will improve scalability, maintainability, and allow independent deployment of services.",
"factSheets": ["API Gateway", "Service Mesh", "Container Orchestration"],
"status": "Proposed"
}
}
```
### Update ADL Entry
```graphql
mutation UpdateEntry($id: ID!, $input: UpdateADLEntryInput!) {
updateADLEntry(id: $id, input: $input) {
id
created
lastEdited
author
title
decision
factSheets
status
}
}
```
**Variables:**
```json
{
"id": "your-entry-id-here",
"input": {
"status": "Approved",
"decision": "Updated decision text with additional context..."
}
}
```
### Delete ADL Entry
```graphql
mutation DeleteEntry($id: ID!) {
deleteADLEntry(id: $id)
}
```
**Variables:**
```json
{
"id": "your-entry-id-here"
}
```
## Example Use Cases
### 1. Create a Proposed Decision
```graphql
mutation {
createADLEntry(input: {
author: "Jane Smith"
title: "Implement GraphQL for API Layer"
decision: "We will use GraphQL instead of REST for our API layer to provide more flexible data fetching and reduce over-fetching issues."
factSheets: ["API Design", "Frontend Architecture", "Backend Services"]
status: Proposed
}) {
id
title
status
}
}
```
### 2. Approve a Decision
```graphql
mutation {
updateADLEntry(
id: "abc-123-def-456"
input: {
status: Approved
}
) {
id
title
status
lastEdited
}
}
```
### 3. Search for Entries by Author
Note: This requires adding a filter parameter to the schema (future enhancement).
Current workaround: Fetch all entries and filter client-side.
```graphql
query {
adlEntries {
id
author
title
status
}
}
```
Then filter in JavaScript:
```javascript
const entries = data.adlEntries.filter(e => e.author === "John Doe");
```
## Testing with cURL
### Query Example
```bash
curl -X POST http://localhost:4000/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "{ adlEntries { id title author status } }"
}'
```
### Mutation Example
```bash
curl -X POST http://localhost:4000/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "mutation($input: CreateADLEntryInput!) { createADLEntry(input: $input) { id title } }",
"variables": {
"input": {
"author": "Test User",
"title": "Test Decision",
"decision": "This is a test",
"factSheets": ["Test"],
"status": "Proposed"
}
}
}'
```
## Using GraphQL Playground
Access the GraphQL Playground at http://localhost:4000/graphql after starting the server.
The playground provides:
- Auto-completion
- Schema documentation
- Query history
- Variable editor
This makes it easy to explore the API and test queries interactively.