Skip to main content
Glama
Apache 2.0
845
2,105
  • Apple
graphql.test.ts2.2 kB
import { stripIndent } from 'common-tags'; import { describe, expect, it } from 'vitest'; import { GraphQLClient } from './graphql.js'; describe('graphql client', () => { it('should load schema', async () => { const schema = stripIndent` schema { query: RootQueryType } type RootQueryType { message: String! } `; const graphqlClient = new GraphQLClient({ url: 'dummy-url', loadSchema: async () => schema, }); const { source } = await graphqlClient.schemaLoaded; expect(source).toBe(schema); }); it('should throw error if validation requested but loadSchema not provided', async () => { const graphqlClient = new GraphQLClient({ url: 'dummy-url', }); await expect( graphqlClient.query( { query: '{ getHelloWorld }' }, { validateSchema: true } ) ).rejects.toThrow('No schema loader provided'); }); it('should throw for invalid query regardless of schema', async () => { const graphqlClient = new GraphQLClient({ url: 'dummy-url', }); await expect( graphqlClient.query({ query: 'invalid graphql query' }) ).rejects.toThrow( 'Invalid GraphQL query: Syntax Error: Unexpected Name "invalid"' ); }); it("should throw error if query doesn't match schema", async () => { const schema = stripIndent` schema { query: RootQueryType } type RootQueryType { message: String! } `; const graphqlClient = new GraphQLClient({ url: 'dummy-url', loadSchema: async () => schema, }); await expect( graphqlClient.query( { query: '{ invalidField }' }, { validateSchema: true } ) ).rejects.toThrow( 'Invalid GraphQL query: Cannot query field "invalidField" on type "RootQueryType"' ); }); it('bubbles up loadSchema errors', async () => { const graphqlClient = new GraphQLClient({ url: 'dummy-url', loadSchema: async () => { throw new Error('Failed to load schema'); }, }); await expect(graphqlClient.schemaLoaded).rejects.toThrow( 'Failed to load schema' ); }); });

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/supabase-community/mcp-supabase'

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