I am new to GraphQL.
Started developing an GraphQL app to pull the data from oracle database.
It is very simple application. The query responds with the resultset
and can be seen results in console.log
; however, it doesn't come to the graphql
window (response/resolver window). It throws the error
Cannot return null for non User.email
I tried the promise in the oracle connection. Not sure, why it is not showing the data in GraphQL.
UserType.js
module.exports = new GraphQLObjectType({
name: 'User',
fields: () => {
return{
id: { type: GraphQLID },
email: { type: new GraphQLNonNull(GraphQLString) }
}
}
});
DBConnection.js
module.exports = oraPool => {
return {
getUsers(apiKey){
return oracledb.createPool(oraConfig).then(function() {
console.log("Connection Pool created");
return oracledb.getConnection().then(function(conn) {
return conn.execute(
//`SELECT 'User ' || JSON_OBJECT ('id' VALUE id, 'email' VALUE email) FROM users where id = :id`
`SELECT * FROM users WHERE id = :id`
,[apiKey]).then(result => {
//console.log(result.metaData);
console.log(humps.camelizeKeys(result.rows[0]));
conn.close();
return humps.camelizeKeys(result.rows[0]);
})
.catch(function(err) {
console.log(err.message);
return connection.close();
});
})
.catch(function(err) {
console.error(err.message);
});
})
}
}
}
Type.js
const RootQueryType = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
user: {
type: UserType,
args: {
key: { type: new GraphQLNonNull(GraphQLString) }
},
resolve: (obj, args, { oraPool }) => {
return oradb(oraPool).getUsers(args.key);
}
}
}
});