Answers.Body: <p>they updated the sourceNodes cycle since this config, you will need to update the schema first doing something like this:</p>
  
  <p>An example using the body hook if you need it:</p>
  
  <pre><code>createSchemaCustomization({ refresh: true }).then(() =&gt; {
      sourceNodes({ webhookBody });
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-10T22:24:09.727Z
Answers.Text: Thanks! Where do I put this?
Answers.UserDisplayName: fxfuture
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-12T13:39:06.663Z
Answers.Text: Around sourceNodes in your developMiddleware
Answers.UserDisplayName: Anthony Ferreol
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-08T11:25:02.327Z
Answers.LastActivityDate: 2020-03-08T11:25:02.327Z
Answers.UserDisplayName: Anthony Ferreol
Body: <p>I am following Andrew Welch's post here - <a href="https://twitter.com/nystudio107/status/1168220713158942720?lang=en" rel="nofollow noreferrer">https://twitter.com/nystudio107/status/1168220713158942720?lang=en</a></p>
  
  <p>I used the gatsby-config.js file he shared here - <a href="https://gist.github.com/monachilada/af7e92a86e0d27ba47a8597ac4e4b105" rel="nofollow noreferrer">https://gist.github.com/monachilada/af7e92a86e0d27ba47a8597ac4e4b105</a></p>
  
  <p>However, when I edit fields in the Live Preview, I get the following error:</p>
  
  <p><strong>UNHANDLED REJECTION Schema must contain uniquely named types but contains multiple types named "Craft".</strong></p>
  
  <pre><code>    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: () =&gt;
                createHttpLink({
                  uri: `${craftGqlUrl}`,
                  headers: {
                    Authorization: `Bearer ${craftGqlToken}`,
                  },
                  fetch: (uri, options) =&gt; {
                    const token = store.get('X-Craft-Token');
                    return fetch(
                      `${uri}${token !== undefined ? `?token=${token}` : ''}`,
                      options,
                   );
                  },
                }),
            },
          },
        ],
        developMiddleware: app =&gt; {
          app.use('*', (req, res, next) =&gt; {
            if (req.query.token) {
              store.set('X-Craft-Token', req.query.token);
              sourceNodes();
            }
            next();
          });
        },
      };
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>
  
Tags: <craft3><live-preview><headless>
Title: Headless Live Preview with Gatsby
ThreadText: # Headless Live Preview with Gatsby
  
  (Asked by: username_0 on 2020-03-06)
  
  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
  
  **Tags:** craft3, live-preview, headless
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-08. Score: 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 });
  });
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks! Where do I put this?  
  > **username_1**: Around sourceNodes in your developMiddleware  
  
  ---
  
  