gatsby-source-sanity
Version:
Gatsby source plugin for building websites using Sanity.io as a backend.
24 lines (23 loc) • 1.42 kB
TypeScript
import { GatsbyContext } from '../types/gatsby';
import { PluginConfig } from '../gatsby-node';
import { StateCache } from './cache';
/**
* Gatsby doesn't generate collection queries for declared third-party schemas,
* and declaring a schema also causes all sorts of weird and hard to debug problems.
*
* This function reads a generated type map of a remote GraphQL schema and generates
* example values for each schema type, then creates Gatsby nodes for each type,
* which results in Gatsby generating queries and schema types that have all the
* possible fields included. Once the schema is created, we remove the mock nodes
* so they are not returned in queries. This is done through a bit of a hack,
* which utilizes the exposed `emitter` on the Gatsby context and listening for
* the `SET_SCHEMA` action to occur. These are internals and might change in the
* future, but we rely on them for now because the alternative is to require data
* to be present and have representative values in all fields before one can start
* writing queries.
*
* There is a community effort (with Gatsby HQ support upcoming) to introduce a
* proper API for declaring schema types, which will make this hack unnecessary.
* Until it lands, this is the best we can do.
*/
export declare function createTemporaryMockNodes(context: GatsbyContext, pluginConfig: PluginConfig, stateCache: StateCache): Promise<void>;