Gatsby: Introspection Query (if not rootType) is not available when creating pages

Created on 2 Jun 2018  路  4Comments  路  Source: gatsbyjs/gatsby

I would like to read my fields available from a specific Type.

__type(name: "datasheet_2") {
    fields {
      name
    }
  }

See image below, it will generate a null result the first time building, but the second time its there!
Suggesting the schema is generated afterwards..

grafik

Is it possible to hook after the update schema step and have the result passed to context of pages?

question or discussion

Most helpful comment

So problem here is that we generate schema twice and we do add suffixes to autogenerated type names that were already defined before. So in createPages (after first schema generateion and before second one) your Datasheet type will most likely be just datasheet (without _2 suffix).

You can also first do introspection query to get type name of datasheet field:

  __type(name:"SpecificationsYaml") {
    fields {
      name
      type {
        name
      }
    }
  }

retrieve type.name for datasheet field and use it and second introspection query.

Ultimate solution in gatsby core to keep types consistent between schema generation runs would be to reset seenNames here https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/create-type-name.js when we start to generate schema ( https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/build-node-types.js#L32 ), but I imagine it would break a lot of pages that use suffixed names in their fragments in page/layout queries. Maybe this is something we can do in v2

All 4 comments

This would solve my case that seems not possible with the graphql specification see https://github.com/gatsbyjs/gatsby/issues/5635

Interesting by quering the root type i get a result by the first build:

  __type(name: "SpecificationsYaml") {
    fields {
      name
    }
  }

so i get title, entryDate, isPromoted, datasheet.. etc.

my data structure is as follows:

title: New Machine T800
entryDate: 21.05.18
isPromoted: true
mediaimages:
  - image: /media/imgkallfass_aus2.jpg
  - image: /media/imgmccain1500_2_small.jpg
datasheet:
  data_available: July 2018
  data_impressions: 22 Mio.
  data_location: Switzerland
  data_units: '6'
  data_year: '2013'
description: |-
  fsfsfsdf saf.
  sdfas

Basically I want to query the fields under Datasheet..

I am using gatsby-transformer-yaml.

So problem here is that we generate schema twice and we do add suffixes to autogenerated type names that were already defined before. So in createPages (after first schema generateion and before second one) your Datasheet type will most likely be just datasheet (without _2 suffix).

You can also first do introspection query to get type name of datasheet field:

  __type(name:"SpecificationsYaml") {
    fields {
      name
      type {
        name
      }
    }
  }

retrieve type.name for datasheet field and use it and second introspection query.

Ultimate solution in gatsby core to keep types consistent between schema generation runs would be to reset seenNames here https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/create-type-name.js when we start to generate schema ( https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/build-node-types.js#L32 ), but I imagine it would break a lot of pages that use suffixed names in their fragments in page/layout queries. Maybe this is something we can do in v2

indeed it worked without suffix..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KyleAMathews picture KyleAMathews  路  3Comments

timbrandin picture timbrandin  路  3Comments

totsteps picture totsteps  路  3Comments

rossPatton picture rossPatton  路  3Comments

brandonmp picture brandonmp  路  3Comments