// Auto-generated from src/ai-service/skills/system/superblocks-api/references/graphql.md
// Do not edit directly - edit the .md file instead
export const content = `# GraphQL Integrations

Reference documentation for working with GraphQL APIs in Superblocks.

## GraphQL Class

\`\`\`typescript
import { GraphQL } from "@superblocksteam/library";

new GraphQL("fetch_users", "graphql-integration-id", {
  query: \`
    query GetUsers($limit: Int!) {
      users(limit: $limit) {
        id
        name
        email
      }
    }
  \`,
  variables: { limit: 10 },
});
\`\`\`

## Output Structure

**IMPORTANT**: GraphQL responses have a specific structure:

\`\`\`typescript
// GraphQL output format
{
  data: {
    users: [...]
  },
  errors?: [...]
}

// Access query results
new JavaScript("process", {
  fn: ({ fetch_users }) => {
    const result = fetch_users.output;
    // Always access via .data property
    return result.data.users;
  }
})
\`\`\`

## Dynamic Queries

\`\`\`typescript
new GraphQL("search", "graphql-id", {
  query: \`
    query SearchUsers($term: String!, $limit: Int) {
      searchUsers(term: $term, limit: $limit) {
        id
        name
        matchScore
      }
    }
  \`,
  variables: ({
    searchTerm,
    pageSize,
  }: {
    searchTerm: string;
    pageSize: number;
  }) => ({
    term: searchTerm,
    limit: pageSize,
  }),
});
\`\`\`

## Mutations

\`\`\`typescript
new GraphQL("create_user", "graphql-id", {
  query: \`
    mutation CreateUser($input: CreateUserInput!) {
      createUser(input: $input) {
        id
        name
        email
        createdAt
      }
    }
  \`,
  variables: ({ name, email }: { name: string; email: string }) => ({
    input: { name, email },
  }),
});
\`\`\`

## Common Patterns

### Query with Fragments

\`\`\`typescript
new GraphQL("complex_query", "graphql-id", {
  query: \`
    fragment UserFields on User {
      id
      name
      email
    }
    
    query GetUsersAndOrders($userId: ID!) {
      user(id: $userId) {
        ...UserFields
        orders {
          id
          total
          status
        }
      }
    }
  \`,
  variables: ({ userId }: { userId: string }) => ({ userId }),
});
\`\`\`

### Pagination with Connections

\`\`\`typescript
new GraphQL("paginated_list", "graphql-id", {
  query: \`
    query ListItems($first: Int!, $after: String) {
      items(first: $first, after: $after) {
        edges {
          node {
            id
            name
          }
          cursor
        }
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
  \`,
  variables: ({ pageSize, cursor }: { pageSize: number; cursor?: string }) => ({
    first: pageSize,
    after: cursor,
  }),
});
\`\`\`

### Batch Operations

\`\`\`typescript
new GraphQL("batch_update", "graphql-id", {
  query: \`
    mutation BatchUpdateItems($updates: [ItemUpdateInput!]!) {
      batchUpdateItems(updates: $updates) {
        success
        updatedCount
        errors {
          itemId
          message
        }
      }
    }
  \`,
  variables: ({ items }: { items: Array<{ id: string; status: string }> }) => ({
    updates: items.map((item) => ({
      id: item.id,
      status: item.status,
    })),
  }),
});
\`\`\`

## Error Handling

GraphQL can return both data and errors:

\`\`\`typescript
new GraphQL("risky_query", "graphql-id", { ... }),

new JavaScript("handle_response", {
  fn: ({ risky_query }) => {
    const result = risky_query.output;

    if (result.errors && result.errors.length > 0) {
      // Handle partial errors
      console.error("GraphQL errors:", result.errors);
    }

    // Data may still be present even with errors
    return result.data?.items ?? [];
  }
})
\`\`\`

## Subscriptions

**Note**: GraphQL subscriptions are not directly supported. For real-time data, consider:

1. Polling with Loop blocks
2. WebSocket integrations if available
3. REST webhook endpoints

## Best Practices

1. **Always select specific fields** - Don't over-fetch
2. **Use variables** - Never interpolate strings in queries
3. **Handle partial responses** - GraphQL can return data with errors
4. **Access via .data** - Always use \`output.data.fieldName\`
5. **Use fragments** - For reusable field selections
`;
//# sourceMappingURL=graphql.generated.js.map