【发布时间】:2018-10-03 22:39:20
【问题描述】:
我找到了一些关于如何使用react-apollo 模拟常规查询的资源。下面的代码就是一个例子:
import ApolloClient from 'apollo-client';
import { ApolloProvider } from 'react-apollo';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { addMockFunctionsToSchema, makeExecutableSchema } from 'graphql-tools';
const schemaString = `
type Model {
id: ID!
}
type Query {
model(modelId: ID!): Model
}
`;
const schema = makeExecutableSchema({ typeDefs: schemaString });
const mocks = {};
addMockFunctionsToSchema({ schema, mocks });
const link = new SchemaLink({ schema });
const client = new ApolloClient({
link,
cache: new InMemoryCache(),
});
但是如何模拟apollo-link-state 查询,即那些标记为@client 的查询?
【问题讨论】:
标签: mocking graphql apollo react-apollo apollo-client