GraphQL Network error: Unexpected end of JSON input using koa-shopify-graphql-proxy

Highlighted
New Member
3 0 0

I'm following tutorial here: https://help.shopify.com/en/api/tutorials/build-a-shopify-app-with-node-and-react

 

Everything had worked fine before I wanted to define custom endpoint for my React app. I've tried to query script tags, but the request to /graphql path was error.

 

I've added `koa-bodyparser`, `koa-router`. Here is my code:

 

app.prepare().then(() => {
    const server = new Koa();
    const router = new Router();
    server.use(removeTrailingSlashes());
    server.use(session(server));
    server.use(favicon(__dirname + '/static/favicon.ico'));
    server.keys = [SHOPIFY_API_SECRET_KEY];
    router.get('/some-path', async (ctx, next) => {});

    router.post('/some-path', async (ctx, next) => {});
    router.get('*', async ctx => {
      await handle(ctx.req, ctx.res)
      ctx.respond = false
    });

    server.use(
      createShopifyAuth({
        apiKey: SHOPIFY_API_KEY,
        secret: SHOPIFY_API_SECRET_KEY,
        scopes: ['write_script_tags','read_script_tags'],
        afterAuth(ctx) {
        const { shop, accessToken } = ctx.session;
        ctx.cookies.set('shopOrigin', shop, { httpOnly: false });
        //implementation
        }
      }),
    );

    server.use(graphQLProxy());
    server.use(verifyRequest());
    server.use(bodyParser());
    server.use(router.routes());
    server.use(router.allowedMethods());


    server.use(async (ctx) => {
      await handle(ctx.req, ctx.res);
      ctx.respond = false;
      ctx.res.statusCode = 200;
      return
    });
    

    server.listen(port, () => {
      console.log(`> Ready on http://localhost:${port}`);
    });

});

 I could query for script tags without the router part above.

0 Likes
Shopify Staff
Shopify Staff
1296 43 188

Would you mind sharing a full stack trace? That might make it easier for us to help out.

0 Likes