I have a small GraphQL query that I want to mock with Apollo's MockedProvider.
export const queryType = new GraphQLObjectType({
name: 'Query',
fields: {
getUsername: {
type: GraphQLString,
resolve: ({ session }) => {
if (session.isLoggedIn) return session.username;
return null;
}
}
}
});
export default new GraphQLSchema({ query: queryType, mutation: mutationType });
I tried adding it to the mocks array, but I couldn't figure out how to convert that query to a format it accepts. My code looks something like this:
const { getUsername } = queryType.getFields();
const mocks = [
{
request: { query: getUsername },
result: { data: { getUsername: 'username' } }
}
];
const app = (
<MockedProvider mocks={mocks}>
<App />
</MockedProvider>
)
I tried to wrap it in gql tag, but it doesn't accept that either. How can I mock this query in my tests?