Skip to main content
Glama
mockGraphQL.ts2.55 kB
import { buildSchema, introspectionFromSchema, type IntrospectionQuery, } from "graphql"; // Simple schema for E2E testing const SIMPLE_SCHEMA_SDL = ` type Query { getUser(id: ID!): User } type Mutation { createUser(name: String!): User } type User { id: ID! name: String! } `; // Create the simple schema and introspection data const simpleSchema = buildSchema(SIMPLE_SCHEMA_SDL); const simpleIntrospectionData = introspectionFromSchema(simpleSchema); // Export the mock data export const mockIntrospectionResult = { data: simpleIntrospectionData, }; export const mockUserExecutionResult = { data: { createUser: { id: "user-123", name: "Jane Doe", }, }, }; // Additional mock data for E2E testing scenarios export const mockGraphQLResponses = { // Success responses introspection: { ok: true, json: async () => mockIntrospectionResult, }, userCreation: { ok: true, json: async () => mockUserExecutionResult, }, // Error responses networkError: { ok: false, status: 500, statusText: "Internal Server Error", }, graphqlError: { ok: true, json: async () => ({ errors: [{ message: "User already exists" }], }), }, authError: { ok: true, json: async () => ({ errors: [ { message: "You must be authenticated to perform this action.", extensions: { code: "UNAUTHENTICATED" }, }, ], }), }, rateLimitError: { ok: true, json: async () => ({ errors: [ { message: "Rate limit exceeded", extensions: { code: "RATE_LIMITED", retryAfter: 60 }, }, ], }), }, } as const; // Helper functions export function createSimpleUserExecutionResult(userData: { id: string; name: string; }) { return { data: { createUser: userData, }, }; } export function createMockErrorResponse( errors: Array<{ message: string; extensions?: Record<string, any> }>, ): { errors: Array<{ message: string; extensions?: Record<string, any> }>; } { return { errors }; } export function createCustomUserResult(id: string, name: string) { return { ok: true, json: async () => createSimpleUserExecutionResult({ id, name }), }; } export function createCustomErrorResponse(message: string, code?: string) { return { ok: true, json: async () => createMockErrorResponse([ { message, ...(code && { extensions: { code } }), }, ]), }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nfishel48/conduit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server