以下のコードはスキーマ全体が1つのファイルに含まれている場合に機能しますが、個々のファイルに分割しようとすると上記のエラーが発生します。エラー:UserCreatePayload.viewerフィールドタイプは出力タイプである必要がありますが、未定義です
すべてのタイプと機能をインポートしています。
詳細を追加する必要がありますが、私は何を言いたいのか分かりません。私はそれが1つのファイルで動作するが、分割されないのでシーケンシングの問題だと思う。
ありがとうございます。
export const viewerType = new GraphQLObjectType({
name: 'Viewer',
fields() {
return {
id: globalIdField('Viewer', ({_id: viewerLocalId}) => {
return viewerLocalId;
}),
_id: {type: GraphQLID},
user: {
type: userType,
resolve(parent, args, {req: {user}}) {
return user || {};
}
},
profile: {
type: profileConnectionType,
args: {
id: {type: GraphQLID},
searchTerm: {type: GraphQLString},
...connectionArgs
},
resolve(parent, {id: profileGlobalId, searchTerm, ...connectionArgs}, {db}) {
const query = (() => {
const q = {};
if (profileGlobalId) {
const {id: profileLocalId} = fromGlobalId(profileGlobalId);
Object.assign(
q,
{_id: new ObjectID(profileLocalId)}
);
}
if (searchTerm) {
Object.assign(
q,
{
$text: {
$search: `\"${searchTerm}\"`
}
}
);
}
return q;
})();
const sort = {_id: -1};
const limit = 0;
return connectionFromPromisedArray(
promisedArrayGet(
query,
sort,
limit,
profileCollectionName,
db
),
connectionArgs
);
}
}
};
},
interfaces: [nodeInterface]
});
class Viewer extends Object {}
export const viewerGet =() => {
return Object.assign(
new Viewer(),
{
_id: 'Viewer'
}
);
};
輸入
const UserCreateMutation = mutationWithClientMutationId({
name: 'UserCreate',
inputFields: {
email: {type: new GraphQLNonNull(GraphQLString)},
password: {type: new GraphQLNonNull(GraphQLString)}
},
outputFields: {
viewer: {
type: viewerType,
resolve() {
return viewerGet();
}
},
field: {
type: userType,
resolve(node) {
return node;
}
}
},
async mutateAndGetPayload({email, password}, {db, req}) {
{viewerType、USERTYPE、viewerGet}
、私はviewerTypeとオブジェクト –
の輸入との質問を更新して、通常の 'module.exports'がうまく – James
がモジュールにそれらを分割追加viewerTypeとviewerTypeのObjectType –