Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.Model = Model;
const name = Model.getTableName();
this.name = name;
/* GraphQLObject */
this.GraphQLType = new GraphQLObjectType({
name,
fields: () => ({
..._.isFunction(fields) ? fields() : fields,
id: globalIdField(name),
}),
interfaces: [nodeInterface],
});
/* GraphQLConnection */
const { connectionType, edgeType } = connectionDefinitions({
name,
nodeType: this.GraphQLType,
...connectionConfig,
});
this.GraphQLConnectionType = connectionType;
this.GraphQLEdgeType = edgeType;
this.GraphQLConnectionField = {
type: this.GraphQLConnectionType,
args: connectionArgs,
resolve: async (root, args) => {
const { after, before, last } = args;
let { first } = args;
if (_.all([first, last], _.isUndefined)) { first = 10; }
return await this.getConnection({ after, first, before, last });
import { FairType } from "schema/v1/fair"
import { pageable, getPagingParameters } from "relay-cursor-paging"
import { connectionDefinitions, connectionFromArraySlice } from "graphql-relay"
import { GraphQLFieldConfig } from "graphql"
import { ResolverContext } from "types/graphql"
export const FollowedFairConnection = connectionDefinitions({
name: "FollowedFair",
// This never ended up being used in the underlying lib.
// edgeType: FollowedFairEdge,
nodeType: FairType,
})
const FollowedFairs: GraphQLFieldConfig = {
type: FollowedFairConnection.connectionType,
args: pageable({}),
description: "A list of the current user’s currently followed fair profiles",
resolve: (_root, options, { followedFairsLoader }) => {
if (!followedFairsLoader) return null
const { limit: size, offset } = getPagingParameters(options)
const gravityArgs = {
size,
const projectType = new GraphQLObjectType({
name: 'Project',
fields: () => ({
id: globalIdField('Project'),
users: {
type: userConnection.connectionType,
args: connectionArgs,
resolve: resolver(models.Project.Users)
}
}),
interfaces: [nodeInterface]
});
const taskConnection = connectionDefinitions({name: 'Task', nodeType: taskType})
, subordinateConnection = connectionDefinitions({name: 'Subordinate', nodeType: userType})
, subtaskConnection = connectionDefinitions({name: 'Subtask', nodeType: taskType})
, userConnection = connectionDefinitions({name: 'User', nodeType: userType});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
projects: {
type: new GraphQLList(projectType),
args: {
limit: {
type: GraphQLInt
},
order: {
type: GraphQLString
}
},
import { pageable } from "relay-cursor-paging"
import { convertConnectionArgsToGravityArgs } from "lib/helpers"
import { GraphQLInt } from "graphql"
import { connectionFromArraySlice, connectionDefinitions } from "graphql-relay"
import { assign } from "lodash"
import { ConversationType } from "./conversation"
export default {
type: connectionDefinitions({
nodeType: ConversationType,
connectionFields: {
totalUnreadCount: {
type: GraphQLInt,
resolve: ({ total_unread_count }) => total_unread_count,
},
},
}).connectionType,
description: "Conversations, usually between a user and partner.",
args: pageable(),
resolve: (root, options, request, { rootValue: { conversationsLoader } }) => {
if (!conversationsLoader) return null
const { page, size, offset } = convertConnectionArgsToGravityArgs(options)
const expand = ["total_unread_count"]
return conversationsLoader({ page, size, expand }).then(
({ total_count, total_unread_count, conversations }) => {
function getConnectionField(graffitiModel, type, hooks = {}) {
const { name } = type;
const { plural } = hooks;
const pluralName = toCollectionName(name.toLowerCase());
const { connectionType } = connectionDefinitions({
name,
nodeType: type,
connectionFields: {
count: {
name: 'count',
type: GraphQLFloat
}
}
});
return {
[pluralName]: {
args: getArguments(type, connectionArgs),
type: connectionType,
resolve: addHooks((rootValue, args, info) => connectionFromModel(graffitiModel, args, info), plural)
}
function _registerConnectionType(registeredType, connectionTypeName) {
const registeredConnectionTypeName = _getRegisteredConnectionTypeName(connectionTypeName);
const registeredConnectionType = types[registeredConnectionTypeName] = connectionDefinitions({ name: connectionTypeName, nodeType: registeredType }).connectionType;
return registeredConnectionType;
}
function rootConnection(name, swapiType) {
const graphqlType = swapiTypeToGraphQLType(swapiType);
const { connectionType } = connectionDefinitions({
name,
nodeType: graphqlType,
connectionFields: () => ({
totalCount: {
type: GraphQLInt,
resolve: conn => conn.totalCount,
description: `A count of the total number of objects in this connection, ignoring pagination.
This allows a client to fetch the first five objects by passing "5" as the
argument to "first", then fetch the total count so it could display "5 of 83",
for example.`,
},
[swapiType]: {
type: new GraphQLList(graphqlType),
resolve: conn => conn.edges.map(edge => edge.node),
description: `A list of all of the objects returned in the connection. This is a convenience
field provided for quickly exploring the API; rather than querying for
const getConnection = (name) => {
if (!connectionTypes[name]) {
connectionTypes[name] = connectionDefinitions({
name,
nodeType: getType(name),
connectionFields: {
totalCount: {
type: GraphQLInt,
description: 'Total number of items',
resolve: connection => {
if (connection.totalCount) {
return connection.totalCount
} else if (connection.edges) {
return connection.edges.length
}
},
},
},
}).connectionType;
export function connectionFromUrls(
name: string,
prop: string,
type: GraphQLObjectType,
): GraphQLFieldConfig<*, *> {
const { connectionType } = connectionDefinitions({
name,
nodeType: type,
resolveNode: edge => edge.node,
connectionFields: () => ({
totalCount: {
type: GraphQLInt,
resolve: conn => conn.totalCount,
description: `A count of the total number of objects in this connection, ignoring pagination.
This allows a client to fetch the first five objects by passing "5" as the
argument to "first", then fetch the total count so it could display "5 of 83",
for example.`,
},
[prop]: {
type: new GraphQLList(type),
resolve: conn => conn.edges.map(edge => edge.node),
description: `A list of all of the objects returned in the connection. This is a convenience
const BuyersPremium = new GraphQLObjectType({
name: "BuyersPremium",
fields: {
...SlugAndInternalIDFields,
amount: amount(({ cents }) => cents),
cents: {
type: GraphQLInt,
resolve: ({ cents }) => cents,
},
percent: {
type: GraphQLFloat,
},
},
})
const saleArtworkConnection = connectionDefinitions({
nodeType: SaleArtwork.type,
}).connectionType
export const SaleType = new GraphQLObjectType({
name: "Sale",
interfaces: [NodeInterface],
fields: () => {
return {
...SlugAndInternalIDFields,
cached,
artworks: {
type: new GraphQLList(Artwork.type),
args: {
page: { type: GraphQLInt, defaultValue: 1 },
size: { type: GraphQLInt, defaultValue: 25 },
all: { type: GraphQLBoolean, defaultValue: false },