Bug/question: E2E testing with GraphQL gives a 401 error #1756
Open
Description
Hi we are working on a shopify app, and as our codebase grows the need for testing E2E rises.
Im currently trying to implement some very basic testing of our backend queries to Shopify. Im initalizing the shopify wrapper using the shopifyApp
function and everything runs smoothly. After initalizing the wrapper with test config:
const prismaSessionStorage = new PrismaSessionStorage(prisma);
let config: Parameters<typeof shopifyApp>[0] | null
if (process.env.NODE_ENV === 'test') {
config = testConfig({
sessionStorage: prismaSessionStorage
});
} else {
// Actual config
}
const shopify_handler = shopifyApp(config);
The following test runs smoothly:
test("Verify that queries are okay", async () => {
const someSession = await prisma.session.findFirstOrThrow()
const {admin} = await shopify_handler.unauthenticated.admin(someSession.shop)
const shop = await admin.rest.get({path: 'shop.json'}).then((r) => r.json())
console.log(shop)
})
I can see in my logs my current dev store
The problem seems to arise when i try to fetch anything from the graphql API
Given the following modified code
test("Verify that queries are okay", async () => {
const someSession = await prisma.session.findFirstOrThrow()
const {admin} = await shopify_handler.unauthenticated.admin(someSession.shop)
const shop = await admin.graphql(`
#graphql
query {
shop {
currencyCode
myshopifyDomain
shopOwnerName
email
contactEmail
plan {
partnerDevelopment
}
}
}
`).then((r) => r.json()).then((data) => {
return data.data.shop
}).catch((e) => {
console.error('Error fetching shop info', e)
return null
})
console.log(shop)
})
I seem to get a 401 unauthenticated error:
Since the rest api calls work as expected i would presume the setup is okay, am i doing something wrong?
Metadata
Assignees
Labels
No labels