, ISO ISO ( languageTag
), , , - :
export default new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
article: {
type: new GraphQLList(ArticleType),
description: 'Content of article dataset',
args: {
id: {
name: 'id',
type: new GraphQLNonNull(GraphQLID)
},
languageTag: {
name: 'languageTag',
type: new GraphQLNonNull(GraphQLString)
}
},
async resolve ({ db }, args) {
return db.collection('articles').find({ main: args.id }).toArray()
}
}
}
})
})
. , ContentType
.
const ContentType = new GraphQLObjectType({
name: 'ContentType',
fields: {
content: {
type: GraphQLString,
resolve: (root, args, context) => root.content[args.languageTag].content
},
timestamp: {
type: GraphQLString,
resolve: (root, args, context) => root.content[args.languageTag].timestamp
}
},
})
, , , article
Array
. , . , : :
export default new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
article: {
type: new GraphQLList(ArticleType),
description: 'Content of article dataset',
args: {
id: {
name: 'id',
type: new GraphQLNonNull(GraphQLID)
},
languageTag: {
name: 'languageTag',
type: new GraphQLNonNull(GraphQLString)
},
fields: {
content: ContentType
}
async resolve ({ db }, args) {
return db.collection('articles').findOne({ main: args.id })
}
}
}
})
})
, . , .