@kiwa-lab/graphql
v2.1.0
Published
GraphQL server / client mock harness for kiwa — Apollo Server / GraphQL Yoga / urql / Relay を統一 interface で invoke する in-process mock。 schema + resolvers 登録、 query / mutation / subscription execution、 WebSocket subscription、 error / extensions handling まで
Downloads
32
Maintainers
Readme
@kiwa-lab/graphql
GraphQL server + client + subscription mock harness for kiwa — Apollo Server / GraphQL Yoga / urql / Relay の 4 pattern を in-process で叩く test infra。
Installation
pnpm add -D @kiwa-lab/graphql
# or
npm install -D @kiwa-lab/graphql
# or
yarn add -D @kiwa-lab/graphqlSupported providers
| Provider | Status | Ops | Subscription | |---|---|---|---| | Apollo Server | ✅ | query / mutation | ✅ | | GraphQL Yoga | ✅ | query / mutation | ✅ | | urql client | ✅ | query / mutation | ✅ | | Relay client | ✅ | query / mutation | ✅ |
Quick start
import { createGraphQLServer, executeQuery, createGraphQLClient } from '@kiwa-lab/graphql';
const server = createGraphQLServer(
{ typeDefs: 'type Query { hello: String }' },
{ Query: { hello: () => 'world' } },
{ provider: 'apollo' },
);
const result = await server.executeQuery('{ hello }');
// result = { data: { hello: 'world' } }
const client = createGraphQLClient(server);
const r2 = await client.request('{ hello }');API reference
createGraphQLServer(schema, resolvers, options?): GraphQLServer— schema + resolvers で mock server 生成GraphQLServer.executeQuery(query, variables?, context?): Promise<GraphQLExecutionResult>— query / mutation dispatchGraphQLServer.listCalls(): GraphQLServerCall[]— 全 call log 取得executeQuery(server, query, variables?, context?)— helper 経由 executioncreateGraphQLClient(server, options?): GraphQLClient— typed client proxy 生成subscribeSubscription(server, query, variables?): SubscriptionHandle— WebSocket subscription mockparseGraphQLOperation(query): ParsedOperation— minimal GraphQL parser
Test integration
import { describe, expect, it } from 'vitest';
import { createGraphQLServer } from '@kiwa-lab/graphql';
describe('user query', () => {
it('name field を resolve', async () => {
const s = createGraphQLServer(
{ typeDefs: 'type Query { name: String }' },
{ Query: { name: () => 'kiwa' } },
);
const r = await s.executeQuery('{ name }');
expect(r.data).toEqual({ name: 'kiwa' });
});
});/kiwa-graphql skill を起動すると query / mutation / subscription 3 経路の test を生成できる。
License
UNLICENSED — see cardene777/kiwa for repo terms.
