Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
const userProfileQuery = gql`
query userProfile($id: ID!) {
userProfile(id: $id)
@rest(type: "User", route: "/users/:id", params: { id: $id }) {
__typename
id
login
}
}
`
const link = createRestLink()
const data = await makePromise(
execute(link, {
operationName: 'userProfile',
query: userProfileQuery,
variables: { id: '2' },
}),
)
expect(data).toEqual({
data: {
userProfile: {
__typename: 'User',
id: '2',
login: 'Jochen',
},
},
})
const query = gql`
query user {
user(id: "2") {
__typename
id
login
friends {
id
login
}
}
}
`
const data = await makePromise(
execute(link, {
operationName: 'user',
query: query,
}),
)
expect(data).toEqual({
data: {
user: {
__typename: 'User',
id: '2',
login: 'Jochen',
friends: [
{
id: `1`,
login: `Peter`,
fetchMock.post('/api/posts', {
headers: { 'Content-Length': 0 },
status: 500,
body: post,
});
const createPostMutation = gql`
mutation publishPost($input: PublishablePostInput!) {
publishedPost(input: $input)
@jsonapi(path: "/posts", method: "POST") {
id
title
}
}
`;
return await makePromise(
execute(link, {
operationName: 'publishPost',
query: createPostMutation,
variables: {
input: {
data: { type: 'posts', attributes: { title: post.title } },
},
},
}),
).catch(e =>
expect(e).toEqual(
new Error('Response not successful: Received status code 500'),
),
);
});
});
expect.assertions(1)
const userProfileQuery = gql`
query userProfile($id: ID!) {
userProfile(id: $id)
@rest(type: "User", route: "/users/:id", params: { id: $id }) {
__typename
id
login
}
}
`
const link = createRestLink()
return makePromise(
execute(link, {
operationName: 'userProfile',
query: userProfileQuery,
}),
).catch(err => {
expect(err.message).toEqual("Missing variable 'id'")
})
})
function exeuteServerQuery(serverUri: string, type: string, headers: Headers) {
const operation = makeOperation(type);
const link = new HttpLink({ uri: serverUri, fetch, headers });
return makePromise(execute(link, operation));
}
return (fetcherOperation: FetcherOperation) => {
return makePromise(execute(link, fetcherOperation as GraphQLRequest));
};
}
headers,
useGETForQueries: method === 'GET'
});
let parsedQuery;
if (typeof query === 'string') {
parsedQuery = new GraphQLDocument(query, this.visitor.io);
await parsedQuery.compile();
} else if (query instanceof GraphQLDocument) {
parsedQuery = query;
} else {
throw new Error(`Unknown type passed to 'query'.`);
}
debug('running query with %o', variables);
return makePromise(
execute(link, { query: await parsedQuery.render(), variables })
)
.then(({ data, errors }) => {
debug(
'query %s with %o resulted in %o',
definition.query,
variables,
{ data, errors }
);
if (errors && errors.length > 0) {
throw new Error(errors[0].message);
} else {
return { data };
}
})
.catch(async e => {
}) => {
const user_info = {
id: user_id,
email,
name,
username,
avatar,
};
const user_identity = {
identity_type: "github",
identity_id: github_id,
user_id,
data,
};
return makePromise(
execute(
link,
makeCreateGithubIdentityOperation({ user_info, user_identity })
)
);
};
export const introspectLink = link =>
introspectionData ||
makePromise(execute(link, { query }))
.then(normalize)
.then(saveIntrospectionData)
.catch(handleConnectionError)