 [ ← blog / 24for2019 ](/) Dec 09, 2019  ·  \#24for2019  ·  2 min read 

# Storing metadata about your Drupal site in Gatsby's schema



While fiddling with Gatsby, I wondered: what about fetching data from Drupal to push into the ***siteMetadata*** array? In the [gatsby-config.js API file](https://www.gatsbyjs.org/docs/api-files-gatsby-config/#site-metadata), you can specify metadata about the site. This is used to store things such as the site's title, a description to be used in meta tags and more. What if I wanted the site name dynamic? Is there a way to manipulate the ***siteMetadata*** during the Gatsby build process?

     ![screenshot of graphiql site metadata](/sites/default/files/styles/large/public/2019-12/Screen%20Shot%202019-12-09%20at%209.23.42%20PM.png?itok=OsQpUDzs) 

 

I did some digging. You can't. The metadata is only populated by the config API file. I tried asking in Drupal Slack. Then I realized I went about it the wrong way. The solution? Just create a new node with only one value. Nodes generate a schema in GraphQL and if there's only one value, you get the one value. Apparently, if there are multiple values that's when you can query. I'm still new to GraphQL, so I have no idea if this is a Gatsby-ism or a GraphQL-ism.

So my idea began to unfold:

- In my theme, add the ***exports.sourceNodes*** hook
- Fetch my JSON:API metadata endpoint, which contains information about the site based on the current domain and storefront.
- Normalize the data and use ***createNode*** to push it into the GraphQL data schema.

The result? Profit!

     ![improved metadata screenshot](/sites/default/files/styles/large/public/2019-12/Screen%20Shot%202019-12-09%20at%209.29.50%20PM.png?itok=eoZ7zgJf) 

 

I was able to build a custom JSON:API endpoint using the JSON:API Resources module that returned the data I needed. This data was then pushed into Gatsby's GraphQL data. And then I could use it for displaying site information - such as the store's address, or dynamically gathering the site's name.

 

  ![](/themes/custom/mglaman/images/headshot.webp)Thanks for reading

I write about Drupal, PHP, and the quiet infrastructure behind large sites — caching, config, and testing. New posts land every week or two.

 [Subscribe via RSS →](/rss.xml) [About me →](/about-me) 

 



 

  [← Older

Drupal + GatsbyJS: GraphQL schema improperly handling multivalued objects

 ](/blog/drupal-gatsbyjs-graphql-schema-improperly-handling-multivalued-objects) [Newer →

PHPStan Drupal: detecting deprecated constants and preparing for PHPStan 0.12 support

 ](/blog/phpstan-drupal-detecting-deprecated-constants-and-preparing-phpstan-012-support)