1

I am following Andrew Welch's post here - https://twitter.com/nystudio107/status/1168220713158942720?lang=en

I used the gatsby-config.js file he shared here - https://gist.github.com/monachilada/af7e92a86e0d27ba47a8597ac4e4b105

However, when I edit fields in the Live Preview, I get the following error:

UNHANDLED REJECTION Schema must contain uniquely named types but contains multiple types named "Craft".

    const { createHttpLink } = require('apollo-link-http');
    const fetch = require('node-fetch');
    const store = require('store');
    const sourceNodes = require('gatsby/dist/utils/source-nodes');
    require('dotenv').config();

    const craftGqlUrl = process.env.CRAFT_GQL_URL;
    const craftGqlToken = process.env.CRAFT_GQL_TOKEN;

    module.exports = {
      plugins: [
        {
          resolve: 'gatsby-source-graphql',
          options: {
            typeName: 'Craft',
            fieldName: 'craft',
            createLink: () =>
              createHttpLink({
                uri: `${craftGqlUrl}`,
                headers: {
                  Authorization: `Bearer ${craftGqlToken}`,
                },
                fetch: (uri, options) => {
                  const token = store.get('X-Craft-Token');
                  return fetch(
                    `${uri}${token !== undefined ? `?token=${token}` : ''}`,
                    options,
                 );
                },
              }),
          },
        },
      ],
      developMiddleware: app => {
        app.use('*', (req, res, next) => {
          if (req.query.token) {
            store.set('X-Craft-Token', req.query.token);
            sourceNodes();
          }
          next();
        });
      },
    };

Any ideas?

Thanks

2

they updated the sourceNodes cycle since this config, you will need to update the schema first doing something like this:

An example using the body hook if you need it:

createSchemaCustomization({ refresh: true }).then(() => {
    sourceNodes({ webhookBody });
});
| improve this answer | |
  • Thanks! Where do I put this? – fxfuture Mar 10 at 22:24
  • Around sourceNodes in your developMiddleware – Anthony Ferreol Mar 12 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.