私はGrpahQLで新しく、ユーザーとグループの多対多の関係をシミュレートしようとしています。私は自分のスキーマで定義されfollowinf種類があります。多対多graphqlスキーマエラー
// UserType.js
const {
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLID } = require('graphql');
const {
GraphQLEmail } = require('graphql-custom-types');
const GroupType = require('./GroupType'); const AuthService = require('../../services/AuthService');
let authService = new AuthService();
const UserType = new GraphQLObjectType({
name: "UserType",
fields:() => ({
id: { type: GraphQLID },
user: { type: GraphQLString },
password: { type: GraphQLString },
name: { type: GraphQLString },
lastname: { type: GraphQLString },
email: { type: GraphQLEmail },
groups: {
type: new GraphQLList(GroupType),
resolve(parentValue) {
return authService.userGroups(userId);
}
}
}) });
module.exports = UserType;
を、これは他のファイルです。何らかの理由で、私はこのエラーを得たので私のために動作しません。この例
// GroupType.js
const {
GraphQLObjectType,
GraphQLString,
GraphQLID,
GraphQLList
} = require('graphql');
const UserType = require('./UserType');
const AuthService = require('../../services/AuthService');
let authService = new AuthService();
const GroupType = new GraphQLObjectType({
name: "GroupType",
fields:() => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
description: { type: GraphQLString },
users: {
type: new GraphQLList(UserType),
resolve(parentArgs) {
return authService.userGroups(parentArgs.id);
}
}
})
});
module.exports = GroupType;
:
Error: Can only create List of a GraphQLType but got: [object Object].
このエラーはGroupTypeに対してのみ発生し、両方が同等の場合にUserTypeに対しては発生しません。何が起きてる?私は間違って何をしていますか?
whitep4nther @ありがとうございました。それは今働く。 – user3005919
@ user3005919答えの横にある灰色の目盛りを使用して、質問に答えたことを示す;) – whitep4nther