【发布时间】:2019-03-20 15:31:07
【问题描述】:
我是 GraphQL 的新手,所以我正在执行我的第一个查询,我正在尝试查询嵌套键 email
这是我的架构
const UserLogin = new GraphQLObjectType({
name: 'UserLoginType',
fields: () => ({
login: { type: GraphQLString },
email: { type: GraphQLString },
}),
});
exports.UserType = new GraphQLObjectType({
name: 'UserType',
fields: () => ({
id: NotNullStringType,
name: { type: GraphQLString },
state: { type: GraphQLString },
login: { type: UserLogin },
}),
});
我要做的是构建一个查询,该查询接受一封电子邮件并搜索 UserType.login.email 值并返回与该电子邮件匹配的第一个值或 null。
谢谢!
编辑:在我的redux/actions.js 文件中我添加了:
export const fetchLoginsByEmail = (userEmail) => {
return createGraphqlAction(
{
query: `
query fetchUserByEmail($userEmail: String!) {
fetchUserByEmail(email: $userEmail) {
login {
email
}
state
name
id
}
}
`,
variables: {
userEmail,
}
},
FETCH_LOGINS_BY_EMAIL,
);
};
在我的query.js 文件中,我的model.exports 对象中有这个:
fetchUserByEmail: {
type: UserType,
resolve: async (source, args, { user, loginId }) => {
if (!user) {
return null;
}
return serailize({
...user,
login: await getLogin(loginId),
});
},
},
【问题讨论】:
标签: javascript graphql