Skip to content

GraphQL Naming Reference

This reference documents the GraphQL naming patterns used throughout the codebase, including file names, operation names, and code generation patterns.

GraphQL files follow a consistent naming pattern that indicates their purpose and which code generation tool processes them.

{directory|fragment}.{type}.{codegen}.graphql

Where:

  • {directory|fragment} - The feature, fragment name, or purpose (e.g., page, validate, imageProps)
  • {type} - The operation type: query, mutation, or fragment
  • {codegen} - The code generation tool: api (Rakiura GraphQL), cms (Contentful), shop (Shopify), or omitted
File NameDescription
page.query.graphqlMain page query (generic)
page.query.cms.graphqlPage query processed by Contentful codegen
validate.query.api.graphqlValidation query for Rakiura GraphQL
product.query.shop.graphqlProduct query for Shopify
imageProps.fragment.graphqlImage properties fragment
submit.mutation.graphqlForm submission mutation
articleListItem.fragment.cms.graphqlArticle fragment for Contentful

The first part of the filename indicates the purpose or what it represents:

page.query.graphql # Main page content query
validate.query.graphql # Validation or existence check
related.query.graphql # Related content query
sidebar.query.graphql # Sidebar content query
imageProps.fragment.graphql # Image properties fragment
metadata.fragment.graphql # Metadata fragment

The second part indicates the GraphQL operation type:

TypeDescriptionUsage
queryData retrieval*.query.graphql
mutationData modification*.mutation.graphql
fragmentReusable selection set*.fragment.graphql

The optional third part indicates which service codegen should pull the schema from:

CodegenDescriptionExtension
cmsContentful GraphQL (via GraphQL Codegen)*.cms.graphql
apiRakiura GraphQL (via GraphQL Codegen)*.api.graphql
shopShopify GraphQL (via GraphQL Codegen)*.shop.graphql
(omitted)Generic query (no codegen)*.query.graphql

The GraphQL operation name (inside the file) follows different conventions.

query {RouteName}{Purpose} {
# fields
}
src/pages/articles/_graphql/page.query.graphql
query ArticlesPage {
articles {
items {
title
slug
}
}
}
# src/pages/articles/[slug]/_graphql/page.query.graphql
query ArticlePage {
article(slug: $slug) {
title
content
}
}
# src/pages/places/_graphql/validate.query.graphql
query ValidatePlacePage {
place(slug: $slug) {
exists
}
}
mutation {Action}{Entity} {
# fields
}
src/components/newsletterForm/graphql/submit.mutation.graphql
mutation SubmitNewsletter {
newsletter {
subscribe(email: $email) {
success
}
}
}
# src/components/contactForm/graphql/send.mutation.graphql
mutation SendContactForm {
contact {
send(data: $data) {
id
status
}
}
}
fragment {EntityName}{Purpose} on {Type} {
# fields
}
src/graphql/fragments/imageProps.fragment.graphql
fragment ImageProperties on Image {
url
width
height
alt
}
# src/graphql/fragments/articleListItem.fragment.graphql
fragment ArticleListItem on Article {
title
slug
excerpt
featuredImage {
...ImageProperties
}
}
# src/graphql/fragments/authorBio.fragment.graphql
fragment AuthorBio on Author {
firstName
lastName
bio
image {
...ImageProperties
}
}
src/pages/{routeName}/_graphql/
├── page.query.graphql # Main page query
├── validate.query.graphql # Validation query
├── api.ts # Exports {routeName}Api()
└── transform.ts # Data transformations

Naming: {routeName} from file path becomes the operation prefix

src/pages/articles/_graphql/page.query.graphql
query ArticlesPage { }
# src/pages/places/_graphql/page.query.graphql
query PlacesPage { }
src/components/{feature}/graphql/
├── query.graphql # Component query
├── api.ts # Exports get{Feature}()
└── transform.ts # Component transforms

Naming: Descriptive based on component purpose

src/components/relatedArticles/graphql/query.graphql
query RelatedArticles { }
# src/components/popularPlaces/graphql/query.graphql
query PopularPlaces { }
src/graphql/fragments/
├── imageProps.fragment.graphql
├── articleListItem.fragment.graphql
└── metadata.fragment.graphql

Naming: Descriptive of the data structure

# Singular for single entities
fragment ImageProperties on Image { }
fragment ArticleListItem on Article { }
# Plural for collections (rare)
fragment ArticleTags on ArticleTagsCollection { }

Files ending in .cms.graphql are processed by GraphQL Codegen with the Contentful schema:

src/pages/articles/_graphql/page.query.cms.graphql
query ArticlesPage {
internalPageCollection(where: { slug: "articles" }) {
items {
title
componentsCollection {
items {
__typename
}
}
}
}
}

Generated types: ArticlesPageQuery, ArticlesPageQueryVariables

Files ending in .api.graphql are for Rakiura GraphQL:

src/components/userProfile/graphql/saves.query.api.graphql
query UserSaves {
saves(userId: $userId) {
id
sourceId
sourceType
}
}

Files ending in .shop.graphql are for Shopify GraphQL:

src/components/productList/graphql/products.query.shop.graphql
query ShopProducts {
products(first: $first) {
edges {
node {
id
title
handle
}
}
}
}

Files without a codegen suffix are generic and may not have generated types:

src/components/search/graphql/query.graphql
query SearchResults {
search(term: $term) {
results {
title
url
}
}
}

✅ Use PascalCase for operation names
✅ Include context in operation names (e.g., ArticlesPage, not just Page)
✅ Match file names to purpose (page.query.graphql for page queries)
✅ Use descriptive fragment names (ImageProperties, not Image)
✅ Include codegen suffix when using code generation (.cms.graphql, .api.graphql, .shop.graphql)
✅ Use singular for entity names in fragments (ArticleListItem, not ArticleListItems)

❌ Use generic operation names (Query, Data, GetData)
❌ Mix naming patterns in the same directory
❌ Omit the operation type suffix (always use .query, .mutation, .fragment)
❌ Use camelCase for operation names
❌ Include implementation details in operation names

{purpose}.{type}.{codegen?}.graphql
ComponentOptionsExample
Purposepage, validate, related, {fragmentName}page, validate
Typequery, mutation, fragmentquery
Codegencms, api, shop, or omitcms
{operationType} {Context}{Purpose} { }
OperationPatternExample
Queryquery {Route}{Purpose}query ArticlesPage
Mutationmutation {Action}{Entity}mutation SubmitNewsletter
Fragmentfragment {Entity}{Purpose} on {Type}fragment ImageProperties on Image