Ich versuche, einen Stardog-Server mit graphql unten ist mein Code abzufragen.Mit Graphql Abfrage Stardog Server mit RDF-Daten
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLInt,
GraphQLString,
GraphQLList,
GraphQLNonNull,
GraphQLID,
GraphQLFloat
} from 'graphql';
import axios from 'axios';
var stardog = require("stardog");
let Noun = new GraphQLObjectType({
name: "Noun",
description: "Basic information on a GitHub user",
fields:() => ({
"c": {
type: GraphQLString,
resolve: (obj) => {
console.log(obj);
}
}
})
});
const query = new GraphQLObjectType({
name: "Query",
description: "First GraphQL for Sparql Endpoint Adaptive!",
fields:() => ({
noun: {
type: Noun,
description: "Noun data from fibosearch",
args: {
noun_value: {
type: new GraphQLNonNull(GraphQLString),
description: "The GitHub user login you want information on",
},
},
resolve: (_,{noun_value}) => {
var conn = new stardog.Connection();
conn.setEndpoint("http://stardog.edmcouncil.org");
conn.setCredentials("xxxx", "xxxx");
conn.query({
database: "jenkins-stardog-load-fibo-30",
query: `select ?c where {?s rdfs:label '${noun_value}'. ?c rdfs:subClassOf ?s}`,
limit: 10,
offset: 0
},
function (data) {
console.log(data.results.bindings);
return data.results.bindings;
});
}
},
})
});
const schema = new GraphQLSchema({
query
});
export default schema;
Abfrage erfolgreich ausgeführt, und ich bin in der Lage das Ergebnis auf der Konsole zu sehen, aber return data.results.bindings;
innen function(data)
kehrt dieses Ergebnis nicht auf die Noun
Typ-System unter dem resolve: (obj) => { console.log(obj); }
und der obj
zurückgegeben null anstelle des Ergebnisses zeigt, bindings
zurückgegeben von der Abfrage von GraphQL. Es wäre toll, wenn mir jemand helfen könnte, herauszufinden, was mir hier fehlt.
Vielen Dank im Voraus, Yashpal
Dank Ahmad, ich den Code nach Ihrem Vorschlag aktualisiert haben, aber Server ist Syntaxfehler für neue Promise ((resolve, ablehnen)) Feld, obwohl Ich habe ein Versprechenspaket installiert und var Promise = require ("promise") gesetzt; – Yashpal
Höchstwahrscheinlich verwenden Sie ES6 nicht. Ich habe die Pfeilfunktion im Code ersetzt. Lassen Sie mich wissen, wenn Sie jetzt einen Syntaxfehler haben. –
Dank einer Million Ahmad bin ich endlich in der Lage, das mit deiner Anleitung zu führen :) – Yashpal