all files / semantic-graphql/src/graphql/ getGraphqlScalarResolver.js

77.78% Statements 7/9
0% Branches 0/4
100% Functions 1/1
87.5% Lines 7/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15                
const isNil = require('../utils/isNil');
const castArrayShape = require('../utils/castArrayShape');
const isGraphqlList = require('./isGraphqlList');
 
function getGraphqlScalarResolver(g, iri) {
  const isList = isGraphqlList(g, iri);
 
  return (source, args, context, info) => Promise.resolve(g.resolvers.resolveSourcePropertyValue(source, iri, context, info))
  // We try to return data that is consistant with the property definition
  // i.e. if it's a list, return an Array
  .then(result => isNil(result) ? isList ? [] : null : castArrayShape(result, isList));
}
 
module.exports = getGraphqlScalarResolver;