我想知道是否可以有条件地创建Construct子句的某些部分。例如,假设我们有以下构造查询:
Construct {-:a a <smth:classtype>.
-:a <smth:attr> ?b} WHERE
{?c a <smth:anotherCalss>.
Optional{?c <smth:anotherAttr> ?b}}
在这种情况下,?b并不总是受限于smth。我只想创建空白节点-:a(如果?b是有界的)。有没有办法在sparql的Construct子句中添加这样的条件?
答案 0 :(得分:3)
您可以在WHERE子句中有条件地创建bnode,方法是将其放在OPTIONAL中:
import {
GraphQLString,
GraphQLBoolean,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
} from 'graphql';
// App Imports
import PostType from '../type';
import { getAll, getById } from '../resolvers';
const ListPostType = new GraphQLObjectType({
name: 'listpost',
description: '...',
fields: () => ({
rows: {
type: new GraphQLList(PostType),
},
count: {
type: GraphQLInt,
},
}),
});
// Post All
export const posts = {
type: ListPostType,
args: {
first: {
type: GraphQLInt,
},
offset: {
type: GraphQLInt,
},
titulo: {
type: GraphQLString,
},
mes: {
type: GraphQLInt,
},
dia: {
type: GraphQLInt,
},
contenido: {
type: GraphQLString,
},
sort: {
type: GraphQLString,
},
destacado: {
type: GraphQLBoolean,
},
order: {
type: GraphQLString,
},
categoria: {
type: GraphQLInt,
},
parent: {
type: GraphQLInt,
},
tag: {
type: GraphQLInt,
},
equipo: {
type: GraphQLInt,
},
},
resolve: getAll,
};
// Post By ID
export const post = {
type: PostType,
args: {
id: { type: new GraphQLNonNull(GraphQLInt) },
},
resolve: getById,
};