Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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);
});
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'
)
})
}
}
}
}
}`
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) ]
)
})
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)
})
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) ]
)
})
resolve: ({ options }) =>
toGlobalId(
"FilterArtworks",
JSON.stringify(omit(options, "page", "offset", "size"))
),
},
resolve: ({ _type, id }) => toGlobalId(_type, id)
},
get relayId(): string {
return toGlobalId('Cat', this.id);
}
}
resolve: item => toGlobalId("SearchableItem", item._id),
},
resolve: (obj, _args, _request, info) => {
return (
(obj._id && toGlobalId(info.parentType.name, obj._id)) ||
(obj.id && toGlobalId(info.parentType.name, obj.id))
)
},
}