以下のGraphQLを使用してstardogサーバーにクエリを実行しようとしています。コードは次のとおりです。
function getResult() {
return {
type: new GraphQLList(GraphQLString),
description: "URI to get data on the people this person follows",
resolve: (obj) => {
console.log(obj);
return obj;
}
};
}
let result = new GraphQLObjectType({
name: "c",
description: "Basic information on a GitHub user",
fields: () => ({
"c": getResult()
})
});
const query = new GraphQLObjectType({
name: "Query",
description: "First GraphQL for Sparql Endpoint!",
fields: () => ({
Noun: {
type: result,
description: "Noun data from ",
args: {
noun_value: {
type: new GraphQLNonNull(GraphQLString),
description: "Noun returns the subclass nouns",
},
},
resolve: (_,{noun_value}) => {
var conn = new stardog.Connection();
conn.setEndpoint("xxxxxx");
conn.setCredentials("xxxx", "xxxx");
return new Promise((resolve, reject) => {
conn.query({
database: "xxxxxx",
query: `select ?c where {?s rdfs:label '${noun_value}'. ?c rdfs:subClassOf ?s}`,
limit: 10,
offset: 0
},
function (data) {
if (data.results.bindings) {
return resolve(data.results.bindings);
} else {
return reject('Null found for data.results.bindings');
}
});
})
}
},
})
});
const schema = new GraphQLSchema({
query
});
export default schema;
;GraphiQL
の間、UIのクエリの解決された結果を取得できません。console.log(obj)
内部getResult
関数は次のように結果を出力します:-
[ { c: { type: 'uri', value: 'spec.edmcouncil.org/fibo/FND/Arrangements/ClassificationSchemes/…; } },
{ c: { type: 'uri', value: 'spec.edmcouncil.org/fibo/FND/Arrangements/Quantities/…; } }]
しかし、GraphiQL UI では、結果は同じようには表示されません。