Apollo GraphQLのMockingの例には、次のコードがあります(下記参照)。mocked実行可能スキーマをApollo Clientに渡すには?
興味深いのは最後の行です。彼らはgraphql
クエリを作成して実行します。しかし、通常、ApolloClientオブジェクトを作成する必要があります。私はそれを行う方法を理解することはできません。
ApolloClientは、実行可能なスキーマではなく、NetworkingInterfaceを引数として想定しています。
したがって、NetworkingInterfaceを使わずに、実行可能なスキーマからApolloClientを作成する方法はありますか?
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import { graphql } from 'graphql';
// Fill this in with the schema string
const schemaString = `...`;
// Make a GraphQL schema with no resolvers
const schema = makeExecutableSchema({ typeDefs: schemaString });
// Add mocks, modifies schema in place
addMockFunctionsToSchema({ schema });
const query = `
query tasksForUser {
user(id: 6) { id, name }
}
`;
graphql(schema, query).then((result) => console.log('Got result', result));
まだ私がマージする必要があるドキュメントには公開されているPRがあります:https://github.com/apollographql/react-docs/pull/172 – stubailo