Skip To Main Content

Seed Query

The Seed Query is a request that is fired when a user is trying to visit a URL which requests data from WP for the given URL. With this data we are able to get a list of possible templates for the given route.

What Is It Used For?

The Seed Query is used for resolving templates in the Faust template hierarchy.

Example Seed Query Request

Here is an example of the seed query that Faust performs behind the scenes before resolving a visited page:

import { gql } from '@apollo/client';

export interface SeedNode {
  __typename?: string;
  uri?: string;
  id?: string;
  databaseId?: string;
  mimeType?: string;
  name?: string;
  isFrontPage?: boolean;
  isPostsPage?: boolean;
  isTermNode?: boolean;
  slug?: string;
  taxonomyName?: string;
  isContentNode?: boolean;
  contentType?: {
    node?: {
      name?: string;
    };
  };
  template?: {
    templateName?: string;
  };
  userId?: number;
}

export const SEED_QUERY = gql`
  query GetNodeByUri($uri: String!) {
    node: nodeByUri(uri: $uri) {
      ...NodeByUri
    }
  }
  fragment NodeByUri on UniformResourceIdentifiable {
    __typename
    uri
    id
    ...DatabaseIdentifier
    ...ContentType
    ...User
    ...TermNode
    ...ContentNode
    ...MediaItem
    ...Page
  }
  fragment DatabaseIdentifier on DatabaseIdentifier {
    databaseId
  }
  fragment MediaItem on MediaItem {
    id
    mimeType
  }
  fragment ContentType on ContentType {
    name
    isFrontPage
    # This is currently broken. The home page (blog page) can not be
    # resolved when set to a custom page until the below issue is resolved.
    # Link: https://github.com/wp-graphql/wp-graphql/issues/2514
    isPostsPage
  }
  fragment Page on Page {
    isFrontPage
    isPostsPage
  }
  fragment TermNode on TermNode {
    isTermNode
    slug
    taxonomyName
  }
  fragment ContentNode on ContentNode {
    isContentNode
    slug
    contentType {
      node {
        name
      }
    }
    template {
      templateName
    }
  }
  fragment User on User {
    name
    userId
    databaseId
  }
`;
Code language: PHP (php)

Depending on the type of the page that is visited, this query will resolve certain fields. For example if there is a page in the /example path in WordPress, the SeedQuery will resolve to:

"data": {
    "node": {
      "__typename": "Page",
      "uri": "/example/",
      "id": "cG9zdDoxNDcw",
      "databaseId": 1470,
      "isContentNode": true,
      "slug": "example",
      "contentType": {
        "node": {
          "name": "page"
        }
      },
      "template": {
        "templateName": "Default"
      },
      "isFrontPage": false,
      "isPostsPage": false
    }
  }

Code language: JavaScript (javascript)

Since this resolved to a node with a page type, the framework will try to match the following templates in order of appearance:

[ 'page-example', 'page-1470', 'page', 'singular', 'index' ]