How to use the graphql-relay.toGlobalId function in graphql-relay

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 acarl005 / join-monster / test / pagination / keyset-paging.js View on Github external
test('should handle root pagination with "first" and "after" args', async t => {
  const query = makeUsersQuery({ first: 2, after: objToCursor({ id: 2 }) })
  const { data, errors } = await run(query)
  errCheck(t, errors)
  t.deepEqual(data.users.pageInfo, {
    hasNextPage: true,
    hasPreviousPage: false,
    startCursor: objToCursor({ id: 3 }),
    endCursor: objToCursor({ id: 4 })
  }, 'page info is accurate')
  t.deepEqual(data.users.edges[0], {
    cursor: objToCursor({ id: 3 }),
    node: {
      id: toGlobalId('User', 3),
      fullName: 'Coleman Abernathy',
      email: 'Lurline79@gmail.com'
    }
  }, 'the first node is accurate')
  t.is(
    data.users.edges.last().cursor,
    data.users.pageInfo.endCursor,
    'the last cursor in edges matches the end cursor in page info'
  )
})
github acarl005 / join-monster / test / pagination / offset-paging.js View on Github external
}
        }
      }
    }
  }`
  const { data, errors } = await run(query)
  errCheck(t, errors)
  t.is(data.users.edges[0].node.id, toGlobalId('User', 1))
  t.deepEqual(
    data.users.edges[0].node.posts.edges.map(edge => edge.node.id),
    [ toGlobalId('Post', 33), toGlobalId('Post', 38) ]
  )
  t.is(data.users.edges[1].node.id, toGlobalId('User', 2))
  t.deepEqual(
    data.users.edges[1].node.posts.edges.map(edge => edge.node.id),
    [ toGlobalId('Post', 1), toGlobalId('Post', 50) ]
  )
})
github acarl005 / join-monster / test / pagination / offset-paging.js View on Github external
const { data, errors } = await run(query)
  errCheck(t, errors)
  const expect = {
    user: {
      fullName: 'Hudson Hyatt',
      following: {
        edges: [
          {
            node: {
              id: toGlobalId('User', 2),
              fullName: 'Hudson Hyatt'
            }
          },
          {
            node: {
              id: toGlobalId('User', 3),
              fullName: 'Coleman Abernathy'
            }
          }
        ]
      }
    }
  }
  t.deepEqual(expect, data)
})
github acarl005 / join-monster / test / pagination / offset-paging.js View on Github external
node {
          id
          fullName
          posts(first: 2, after: "${offsetToCursor(1)}") {
            edges {
              cursor
              node { id, body }
            }
          }
        }
      }
    }
  }`
  const { data, errors } = await run(query)
  errCheck(t, errors)
  t.is(data.users.edges[0].node.id, toGlobalId('User', 1))
  t.deepEqual(
    data.users.edges[0].node.posts.edges.map(edge => edge.node.id),
    [ toGlobalId('Post', 33), toGlobalId('Post', 38) ]
  )
  t.is(data.users.edges[1].node.id, toGlobalId('User', 2))
  t.deepEqual(
    data.users.edges[1].node.posts.edges.map(edge => edge.node.id),
    [ toGlobalId('Post', 1), toGlobalId('Post', 50) ]
  )
})
github artsy / metaphysics / src / schema / v1 / filter_artworks.ts View on Github external
resolve: ({ options }) =>
        toGlobalId(
          "FilterArtworks",
          JSON.stringify(omit(options, "page", "offset", "size"))
        ),
    },
github davidfrtala / curriculum-vitae / src / schema.js View on Github external
      resolve: ({ _type, id }) => toGlobalId(_type, id)
    },
github kazekyo / nestjs-graphql-relay / src / cats / models / cat.model.ts View on Github external
get relayId(): string {
    return toGlobalId('Cat', this.id);
  }
}
github artsy / metaphysics / src / schema / SearchableItem / index.ts View on Github external
      resolve: item => toGlobalId("SearchableItem", item._id),
    },
github artsy / metaphysics / src / schema / v2 / object_identification.ts View on Github external
resolve: (obj, _args, _request, info) => {
    return (
      (obj._id && toGlobalId(info.parentType.name, obj._id)) ||
      (obj.id && toGlobalId(info.parentType.name, obj.id))
    )
  },
}