Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fields: () => ({
id: Relay.globalIdField('User'),
username: {
type: GraphQL.GraphQLString,
description: 'the User name',
resolve: (user) => {
// console.log(user.username);
return user.username;
},
},
images: {
type: ImageConnectionType,
description: 'A collection of images',
args: Relay.connectionArgs,
resolve: (_, args) => Relay.connectionFromPromisedArray(
(new MyImages()).getAll(),
args
),
},
}),
interfaces: [nodeDefinition.nodeInterface],
// If the class doesn't have any filter, using `{}` as `filters` field would throw an error
// This little hack prevents it
var filtersHolder = !(0, _lodash.keys)(filtersFields).length ? {} : {
filters: {
type: filtersType
}
};
// lowerCaseName
var lcName = className.toLowerCase();
// All
queries[pluralName] = {
type: classesFieldsHelper._connections[lcName],
args: _extends({}, _graphqlRelay.connectionArgs, filtersHolder, { // Here we destructure our potentially empty object
orderBy: {
type: new _graphql.GraphQLList(orderByType)
}
}),
resolve: function resolve(_, args) {
// Create query
var query = {};
(0, _lodash.each)(args.filters, function (filter, fieldName) {
var safeFilter = (0, _lodash.cloneDeep)(filter);
// RegExp process
if (safeFilter.regexp) {
var matchedRegexp = safeFilter.regexp.match(/\/(.*)\/(\w*)/);
if (!matchedRegexp) {
throw new Error('Invalid RegExp at ' + className + '/' + fieldName);
type: Node,
args: {
name: {type: GraphQLString},
},
async resolve(root, {name}, {loaders}) {
return await loaders.nodeByIdLoader.load(name);
}
},
root: {
async resolve(_) { return {foo: 'bar'}; },
type: new GraphQLObjectType({
name: 'RootType',
fields: {
namespaces: {
type: AllNamespacesConnection,
args: GraphQLRelay.connectionArgs,
async resolve(root, args, {loaders}) {
const namespaces = await loaders.allNamespaces;
return GraphQLRelay.connectionFromArray(namespaces, args);
},
},
kubeNodes: {
type: AllNodesConnection,
args: GraphQLRelay.connectionArgs,
async resolve(root, args, {loaders}) {
const nodes = await loaders.allNodes;
return GraphQLRelay.connectionFromArray(nodes, args);
}
},
pods: {
type: AllPodsConnection,
args: {
root: {
async resolve(_) { return {foo: 'bar'}; },
type: new GraphQLObjectType({
name: 'RootType',
fields: {
namespaces: {
type: AllNamespacesConnection,
args: GraphQLRelay.connectionArgs,
async resolve(root, args, {loaders}) {
const namespaces = await loaders.allNamespaces;
return GraphQLRelay.connectionFromArray(namespaces, args);
},
},
kubeNodes: {
type: AllNodesConnection,
args: GraphQLRelay.connectionArgs,
async resolve(root, args, {loaders}) {
const nodes = await loaders.allNodes;
return GraphQLRelay.connectionFromArray(nodes, args);
}
},
pods: {
type: AllPodsConnection,
args: {
...GraphQLRelay.connectionArgs,
namespace: {type: GraphQLString},
},
async resolve(root, {namespace, ...args}, {loaders}) {
const nodes = await loaders.podsByNamespaceLoader.load(namespace || "");
return GraphQLRelay.connectionFromArray(nodes, args);
}
}
}
},
boards: {
type: _BoardConnection["default"].connectionType,
args: _objectSpread({}, _graphqlRelay.connectionArgs, {
search: {
type: _graphql.GraphQLString
}
}),
resolve: function resolve(_, args, context) {
return BoardLoader.loadBoards(context, args);
}
},
boardIos: {
type: _BoardIoConnection["default"].connectionType,
args: _objectSpread({}, _graphqlRelay.connectionArgs, {
search: {
type: _graphql.GraphQLString
}
}),
resolve: function resolve(_, args, context) {
return BoardIoLoader.loadBoardIos(context, args);
}
}
};
}
});