首先感谢您阅读本文,我花了最后一天的时间来解决这个我根本无法弄清楚的错误。我之前有它工作过,但由于某种原因它停止了。基本上,所有服务都按预期独立工作。但是,一旦我尝试引用另一个(假设我正在使用配置文件服务并想从帐户服务中提取电子邮件),它只会返回 null。没有错误信息,什么都没有。我已经添加了重要的代码片段,但如果您想查看整个代码库,请告诉我,我会将其推送到 github。
帐户类型定义:
import { gql } from 'apollo-server';
const typeDefs = gql`
# SCALARS
"""
An ISO 8601-encoded UTC date string...
"""
scalar DateTime
# OBJECTS
"""
An account is an Auth0 user that provides authentication details.
"""
type Account @key(fields: "id") {
"The unique Auth0 ID associated with the account."
id: ID!
"The date and time the account was created."
createdAt: DateTime!
"The email associated with the account (must be unique)."
email: String
"Whether the account is blocked."
isBlocked: Boolean
"Whether the account has a moderator role."
isModerator: Boolean
}
帐户解析器:
Account: {
__resolveReference(reference, { dataSources }, info) {
return dataSources.accountsAPI.getAccountById(reference.id);
},
id(account, args, context, info) {
return account.user_id;
},
createdAt(account, args, context, info) {
return account.created_at;
},
isModerator(account, args, context, info) {
return (
account.app_metadata &&
account.app_metadata.roles &&
account.app_metadata.roles.includes('moderator')
);
},
isBlocked(account, args, context, info) {
return account.blocked;
},
},
配置文件类型定义:
extend type Account @key(fields: "id") {
id: ID! @external
"Metadata about the user that owns the account."
profile: Profile
}
type Profile @key(fields: "id") {
"The unique MongoDB document ID of the user's profile."
id: ID!
"The Auth0 account tied to this profile."
account: Account!
"The URL of the user's avatar."
avatar: String
"A short bio or description about the user (max. 256 characters)."
description: String
"Other users that the user follows."
following(
first: Int
after: String
last: Int
before: String
orderBy: ProfileOrderByInput
): ProfileConnection
"The full name of the user."
fullName: String
"The URL of the user's GitHub page."
githubUrl: String
"The user's pinned GitHub repositories and gists."
pinnedItems: [PinnableItem]
"The unique username of the user."
username: String!
"Whether the currently logged in user follows this profile."
viewerIsFollowing: Boolean
}
轮廓解析器:
Profile: {
account(profile, args, context, info) {
return { __typename: 'Account', id: profile.account_id };
},
}