是否可以在 Apollo 模拟中传递参数?
在 Apollo docs 它显示了这个例子:
const { ApolloServer, gql } = require('apollo-server');
const typeDefs = gql`
type Query {
hello: String
resolved: String
}
`;
const resolvers = {
Query: {
resolved: () => 'Resolved',
},
};
const mocks = {
Int: () => 6,
Float: () => 22.1,
String: () => 'Hello',
};
const server = new ApolloServer({
typeDefs,
resolvers,
mocks,
});
server.listen().then(({ url }) => {
console.log(`
In the Apollo docs it shows this example:
const { ApolloServer, gql } = require('apollo-server');
const typeDefs = gql`
type Query {
hello: String
resolved: String
}
`;
const resolvers = {
Query: {
resolved: () => 'Resolved',
},
};
const mocks = {
Int: () => 6,
Float: () => 22.1,
String: () => 'Hello',
};
const server = new ApolloServer({
typeDefs,
resolvers,
mocks,
});
server.listen().then(({ url }) => {
console.log(`???? Server ready at ${url}`)
});
I want to be able to pass in an argument, such as an ID into it, like:
const mocks = {
Job: (id) => {
return somearray.filter(_id === id)
},
};
Is this possible with Apollo?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Apollo 服务器 V3 上,您需要使用不同类型的代码。它与 V2 相比有一些重大变化。
您可以通过以下代码来做到这一点:
On Apollo server V3 you need to use a different kind of code. It has some breaking changes from V2.
You can do that by following the code below: