私はgraphqlで非常に新しいです。私は単純なケースで遊んでいますし、ユーザは多くの音符を有し、1つの音符はユーザに属する。 私の問題は、私は(いくつかのフィールドを削除する重要)注意事項はありませんのUserTypeエラー:Note.userフィールドタイプは出力タイプでなければなりませんが、オブジェクトオブジェクトを持っている必要があります:
コードを作成するユーザーのユーザー名を返すことができる「NoteType」私は返すことはできません「のUserType」である
NoteType私はエラーエラー持たユーザーデ私がコメントを解除
:フィールド型Note.userでなければなりません出力タイプをしかし得た:[オブジェクトOBJE ct]。
import {
GraphQLObjectType,
GraphQLInt,
GraphQLString,
GraphQLBoolean,
} from 'graphql';
import UserType from '../User/UserType';
import User from '../User/User';
const NoteType = new GraphQLObjectType({
name: 'Note',
description: 'This represents a Note',
fields:() => ({
id: {
type: GraphQLInt,
resolve: (note) => note.id,
},
userId: {
type: GraphQLInt,
resolve: (note) => note.userId,
},
title: {
type: GraphQLString,
resolve: (note) => note.note,
},
username: {
type: GraphQLString,
resolve: (note) => (
User
.findOne({
where: {
id: note.userId,
},
}).then(user => user.username)
),
},
/* user: { ***PROBLEM HERE!!***
type: UserType,
resolve: (note) => (
User
.findOne({
where: {
id: note.userId,
},
}).then(user => user)
),
},*/
}),
});
module.exports = NoteType;
のUserType
import {
GraphQLObjectType,
GraphQLInt,
GraphQLString,
GraphQLList,
} from 'graphql';
import NoteType from '../Note/NoteType';
import Note from '../Note/Note';
import LocationType from '../Location/LocationType';
import Location from '../Location/Location';
const UserType = new GraphQLObjectType({
name: 'User',
description: 'This represents a User',
fields:() => ({
id: {
type: GraphQLInt,
resolve: (user) => user.id,
},
username: {
type: GraphQLString,
resolve: (user) => user.username,
},
email: {
type: GraphQLString,
resolve: (user) => user.email,
},
notes: {
type: new GraphQLList(NoteType),
resolve: (user) => (
Note
.findAll({
where: {
userId: user.id,
},
})
),
},
}),
});
module.exports = UserType;
NoteQuery
import {
GraphQLInt,
GraphQLString,
GraphQLList,
} from 'graphql';
import NoteType from '../../models/Note/NoteType';
import Note from '../../models/Note/Note';
import UserType from '../../models/User/UserType';
import User from '../../models/User/User';
const noteQuery = {
type: new GraphQLList(NoteType),
args: {
id: {
name: 'id',
type: GraphQLInt,
},
userId: {
name: 'userId',
type: GraphQLInt,
},
user: {
name: 'user',
type: GraphQLString,
},
note: {
name: 'note',
type: GraphQLString,
},
createdAt: {
name: 'createdAt',
type: GraphQLString,
},
updatedAt: {
name: 'updatedAt',
type: GraphQLString,
},
},
resolve: (user, args) => Note.findAll({ where: args }),
};
module.exports = noteQuery;
UserQuery
import {
GraphQLInt,
GraphQLString,
GraphQLList,
} from 'graphql';
import UserType from '../../models/User/UserType';
import User from '../../models/User/User';
const userQuery = {
users: {
type: new GraphQLList(UserType),
args: {
id: {
name: 'id',
type: GraphQLInt,
},
username: {
name: 'username',
type: GraphQLString,
},
email: {
name: 'email',
type: GraphQLString,
},
createdAt: {
name: 'createdAt',
type: GraphQLString,
},
updatedAt: {
name: 'updatedAt',
type: GraphQLString,
},
},
resolve: (user, args) => User.findAll({ where: args }),
},
user: {
type: UserType,
args: {
id: {
name: 'id',
type: GraphQLInt,
},
username: {
name: 'username',
type: GraphQLString,
},
email: {
name: 'email',
type: GraphQLString,
},
createdAt: {
name: 'createdAt',
type: GraphQLString,
},
updatedAt: {
name: 'updatedAt',
type: GraphQLString,
},
},
resolve: (user, args) => User.findOne({ where: args }),
},
};
module.exports = userQuery;
ご協力いただきありがとうございます。
ありがとうございます、私は、ヒントのおかげで、調査します! – Julieta