У меня другая проблема с исходным кодом GraphQL / Sequelize. Похоже, что мои преобразователи не используются во время выполнения. В настоящее время решатель, похоже, вызывается для верхнего типа вывода (Page), но распознаватель для второго типа вывода (Content) не вызывается.
Запрос, отправленный интерфейсом:
query {
pages (hidden: false) { // this resolver is called (Page)
id
label
paragraphs (hidden: false) { // but not this one... (Content)
id
heading
text
}
}
}
Определение пакета запроса:
import pageFields from './fields/page';
import contentFields from './fields/content';
const QueryBundle = new GraphQLObjectType({
name: 'Query',
description: 'This is the root query',
fields: () => {
return {
pages: pageFields,
paragraphs: contentFields
};
}
});
Файл pageFields:
import Page from '../types/page';
import PageParagraph from '../inputs/content';
import db from '../db';
// This is the Page's fields for the QueryBundle definition...
const pageFields = {
type: new GraphQLList(Page),
args: {
id: {
type: GraphQLInt
},
label: {
type: GraphQLString
},
hidden: {
type: GraphQLBoolean
},
paragraphs: {
type: new GraphQLList(PageParagraph)
}
},
async resolve(parent, args) {
return await db.models.page.findAll({
include: [{
all: true,
nested: true
}],
where: args
});
}
};
export default pageFields;
Примечание: этот преобразователь будет вызываться, и инструмент GraphiQL, и терминал отобразят SELECT query ...
Файл contentFields:
import Content from '../types/content';
import db from '../db';
// This is the Content's fields for the QueryBundle definition...
const contentFields = {
type: new GraphQLList(Content),
args: {
id: {
type: GraphQLInt
},
heading: {
type: GraphQLString
},
text: {
type: GraphQLString
},
hidden: {
type: GraphQLBoolean
}
},
async resolve(parent, args) {
return await db.models.content.findAll({
include: [{
all: true,
nested: true
}],
where: args
});
}
};
export default contentFields;
Примечание. Но этот файл никогда не вызывается, почему? Любые аргументы, которые я использую в запросе, будут проигнорированы, так как он никогда не достигает этой точки ...