Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

fragment preview support #10

Closed
ffdead opened this issue Mar 14, 2019 · 4 comments
Closed

fragment preview support #10

ffdead opened this issue Mar 14, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@ffdead
Copy link

ffdead commented Mar 14, 2019

Is there a recommended way of defining GraphQL fragments so that the Apollo client knows about them?

Currently when I defined a fragment in a component like this:

export const query = graphql`
  fragment SiteSettings on PRISMIC_Site_settings {
    ...
  }
`

The preview throws this error:

index.js:2177 Failed to fetch preview Error: Network error: Response not successful: Received status code 500
    at new ApolloError (bundle.esm.js:60)

Response:

{"message":"Query does not pass validation. Violations:\n\nUnknown fragment 'SiteSettings'. (line 30, column 5):\n    ...SiteSettings\n    ^"}

So it seems as if the fragment is unknown at this point.


Sorry for the storm of new issues. We really hope to use this plugin on a project to enable the preview functionality. I'm reporting what I find and hope it helps someone in the future :)

@birkir birkir added question Further information is requested enhancement New feature or request and removed question Further information is requested labels Mar 14, 2019
@birkir
Copy link
Owner

birkir commented Mar 14, 2019

We should be able to support fragments like the gatsby-source-graphql-universal https://github.com/birkir/gatsby-source-graphql-universal/blob/d743dad75cc9e47e6950e634c3fa8b9292d3e12d/src/index.js#L114

@birkir
Copy link
Owner

birkir commented Mar 20, 2019

Fixed in 2.3.3 and 3.0.0

@birkir birkir closed this as completed Mar 20, 2019
@ffdead
Copy link
Author

ffdead commented Mar 20, 2019

Still not working with v2.3.3

Using a Fragment still generates an error with active Preview cookie:

"Query does not pass validation. Violations:↵↵Unknown fragment 'MyTestFrag'. (line 3, column 5):↵ ...MyTestFrag↵ ^"

This is the test code, which renders ok when not in Preview mode:

import { graphql } from 'gatsby'

import GlobalHome from 'views/global-home/GlobalHome'

export const myFrag = graphql`
  fragment MyTestFrag on PRISMIC_Global_home {
    title
  }
`

export const query = graphql`
  query Home {
    prismic {
      global_home(uid: "home", lang: "en-us") {
        ... MyTestFrag
      }
    }
  }
`

GlobalHome.query = query

export default GlobalHome

@ffdead
Copy link
Author

ffdead commented Mar 21, 2019

Confirmed it's working in v3.0.0-alpha.21 using this syntax: https://github.com/birkir/gatsby-source-prismic-graphql#fragments

Good stuff!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants