How to use graphql-relay - 10 common examples

To help you get started, we’ve selected a few graphql-relay examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github entria / graphql-dataloader-boilerplate / src / interface / __tests__ / NodeInterface.spec.js View on Github external
// language=GraphQL
  const query = `
    query Q($id: ID!) {
      node(id: $id) {
        id
        ... on User {
          name
        }
      }
    }
  `;

  const rootValue = {};
  const context = getContext();
  const variables = {
    id: toGlobalId('User', user.id),
  };

  const result = await graphql(schema, query, rootValue, context, variables);
  expect(result.data.node.id).toBe(variables.id);
  expect(result.data.node.name).toBe(user.name);
});
github DefinitelyTyped / DefinitelyTyped / graphql-relay / graphql-relay-tests.ts View on Github external
globalIdField,
    pluralIdentifyingRootField,
    // Mutations
    mutationWithClientMutationId,
} from "graphql-relay";
// Connections
// connectionArgs returns the arguments that fields should provide when they return a connection type that supports bidirectional pagination.
connectionArgs.first = 10;
connectionArgs.after = "a";
connectionArgs.before = "b";
connectionArgs.last = 10;
// forwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports forward pagination.
forwardConnectionArgs.after = "a";
forwardConnectionArgs.first = 10;
// backwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports backward pagination.
backwardConnectionArgs.before = "b";
backwardConnectionArgs.last = 10;
// connectionDefinitions returns a connectionType and its associated edgeType, given a node type.
const resolve: GraphQLFieldResolver = (source, args, context, info) => {
    info.fieldName = "f";
};
const fields: GraphQLFieldConfigMap = {};
let t: GraphQLObjectType;
let e: GraphQLObjectType;
const def = connectionDefinitions({
    connectionFields: fields,
    edgeFields: fields,
    name: "N",
    nodeType: new GraphQLObjectType({
        name: "N",
        fields: {},
    }),
github DefinitelyTyped / DefinitelyTyped / graphql-relay / graphql-relay-tests.ts View on Github external
pluralIdentifyingRootField,
    // Mutations
    mutationWithClientMutationId,
} from "graphql-relay";
// Connections
// connectionArgs returns the arguments that fields should provide when they return a connection type that supports bidirectional pagination.
connectionArgs.first = 10;
connectionArgs.after = "a";
connectionArgs.before = "b";
connectionArgs.last = 10;
// forwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports forward pagination.
forwardConnectionArgs.after = "a";
forwardConnectionArgs.first = 10;
// backwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports backward pagination.
backwardConnectionArgs.before = "b";
backwardConnectionArgs.last = 10;
// connectionDefinitions returns a connectionType and its associated edgeType, given a node type.
const resolve: GraphQLFieldResolver = (source, args, context, info) => {
    info.fieldName = "f";
};
const fields: GraphQLFieldConfigMap = {};
let t: GraphQLObjectType;
let e: GraphQLObjectType;
const def = connectionDefinitions({
    connectionFields: fields,
    edgeFields: fields,
    name: "N",
    nodeType: new GraphQLObjectType({
        name: "N",
        fields: {},
    }),
    resolveCursor: resolve,
github DefinitelyTyped / DefinitelyTyped / graphql-relay / graphql-relay-tests.ts View on Github external
connectionFromArray,
    connectionFromPromisedArray,
    cursorForObjectInConnection,
    // Object Identification
    nodeDefinitions,
    toGlobalId,
    fromGlobalId,
    globalIdField,
    pluralIdentifyingRootField,
    // Mutations
    mutationWithClientMutationId,
} from "graphql-relay";
// Connections
// connectionArgs returns the arguments that fields should provide when they return a connection type that supports bidirectional pagination.
connectionArgs.first = 10;
connectionArgs.after = "a";
connectionArgs.before = "b";
connectionArgs.last = 10;
// forwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports forward pagination.
forwardConnectionArgs.after = "a";
forwardConnectionArgs.first = 10;
// backwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports backward pagination.
backwardConnectionArgs.before = "b";
backwardConnectionArgs.last = 10;
// connectionDefinitions returns a connectionType and its associated edgeType, given a node type.
const resolve: GraphQLFieldResolver = (source, args, context, info) => {
    info.fieldName = "f";
};
const fields: GraphQLFieldConfigMap = {};
let t: GraphQLObjectType;
let e: GraphQLObjectType;
const def = connectionDefinitions({
github DefinitelyTyped / DefinitelyTyped / graphql-relay / graphql-relay-tests.ts View on Github external
connectionFromPromisedArray,
    cursorForObjectInConnection,
    // Object Identification
    nodeDefinitions,
    toGlobalId,
    fromGlobalId,
    globalIdField,
    pluralIdentifyingRootField,
    // Mutations
    mutationWithClientMutationId,
} from "graphql-relay";
// Connections
// connectionArgs returns the arguments that fields should provide when they return a connection type that supports bidirectional pagination.
connectionArgs.first = 10;
connectionArgs.after = "a";
connectionArgs.before = "b";
connectionArgs.last = 10;
// forwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports forward pagination.
forwardConnectionArgs.after = "a";
forwardConnectionArgs.first = 10;
// backwardConnectionArgs returns the arguments that fields should provide when they return a connection type that only supports backward pagination.
backwardConnectionArgs.before = "b";
backwardConnectionArgs.last = 10;
// connectionDefinitions returns a connectionType and its associated edgeType, given a node type.
const resolve: GraphQLFieldResolver = (source, args, context, info) => {
    info.fieldName = "f";
};
const fields: GraphQLFieldConfigMap = {};
let t: GraphQLObjectType;
let e: GraphQLObjectType;
const def = connectionDefinitions({
    connectionFields: fields,
github danscan / datomic-graphql / src / graphQLSchema / utils / getNodeDefinitions.js View on Github external
export default function getNodeDefinitions(apiUrl, dbAlias) {
  const db = consumer(apiUrl, dbAlias);

  return nodeDefinitions(
    (globalId) => {
      const { type, id } = fromGlobalId(globalId);

      return db.getEntity(id)
        .then(entity => {
          console.log(`type "${type}" entity:`, entity);
          return entity;
        });
    },
    (object) => {
      console.log('get GraphQL type of object:', object);
      // const registeredType = getRegisteredTypeForValueType(object.__type);

      // FIXME: Return object type from node interface...
      return null;
    }
github bfwg / relay-gallery / schema / schema.js View on Github external
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],
github OpenCTI-Platform / opencti / opencti-platform / opencti-graphql / src / database / grakn.js View on Github external
export const listRelations = async (relationType, relationFilter, args) => {
  const searchFields = ['name', 'description'];
  const { first = 200, after, orderBy, orderMode = 'asc', withCache = true, inferred = false } = args;
  const { search, fromRole, fromId, toRole, toId, fromTypes = [], toTypes = [] } = args;
  const { firstSeenStart, firstSeenStop, lastSeenStart, lastSeenStop, weights = [] } = args;
  const offset = after ? cursorToOffset(after) : 0;
  const isRelationOrderBy = orderBy && includes('.', orderBy);
  // Handle relation type(s)
  const relationToGet = relationType || 'stix_relation';
  // 0 - Check if we can support the query by Elastic
  const unsupportedOrdering = isRelationOrderBy && last(orderBy.split('.')) !== 'internal_id_key';
  const supportedByCache = !unsupportedOrdering && !relationFilter && !inferred;
  const useCache = !forceNoCache() && withCache && supportedByCache;
  if (useCache) {
    const filters = [];
    const relationsMap = new Map();
    if (fromId) {
      filters.push({ key: 'connections.internal_id_key', values: [fromId] });
      relationsMap.set(fromId, { alias: 'from', internalIdKey: fromId });
    }
    if (toId) {
      filters.push({ key: 'connections.internal_id_key', values: [toId] });
github renanmav / relayable / packages / server / src / modules / question / mutation / DeleteQuestion.ts View on Github external
mutateAndGetPayload: async (data, { user }: GraphQLContext) => {
    if (!user) return { error: 'You must be authenticated' }

    const { id } = fromGlobalId(data.id)

    const question = await QuestionModel.findById(id)
    if (!question) return { error: "Question doesn't exists" }

    // eslint-disable-next-line eqeqeq
    if (question.author.toString() != user._id) {
      return { error: "You don't own this question" }
    }

    await QuestionModel.findByIdAndDelete(id)

    return { error: null }
  },
  outputFields: {
github bitriddler / VineRelayStore / server / graphql / types / orderItemType.js View on Github external
fields: () => ({
    id: globalIdField('OrderItem'),
    quantity: { type: new GraphQLNonNull(GraphQLInt) },
    product: {
      // This can be null if product has been removed
      type: productType,
      resolve: (item) => item.getProduct(),
    },
  }),
  interfaces: [nodeInterface],