npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@labdigital/storyblok-graphql-codegen-terraform

v0.13.1

Published

This is a plugin for GraphQL Codegen that outputs your schema to Storyblok resources in Terraform.

Downloads

687

Readme

storyblok-graphql-codegen-terraform

This is a plugin for GraphQL Codegen that outputs your schema to Storyblok resources in Terraform.

This terraform code is dependent on the Storyblok Terraform provider.

For an example output see the example output terraform file.

For more information on the Storyblok Terraform provider, see the documentation on the terraform registry.

codegen.yml

A basic example:

overwrite: true
config:
  sort: false
schema:
  - storyblok-graphql-codegen-terraform
  - ./schemas/example.graphql
hooks:
  afterAllFileWrite:
    - terraform fmt
generates:
  terraform/example.tf:
    plugins:
      - storyblok-graphql-codegen-terraform
    config:
      space_id: 123
      sort_resources: true

Configuration options

  • sort_resources can be used to sort the resources in the terraform output. This can be used to avoid random sorting which can cause differences in your git changes each time you run the codegenerator. It is also adviced to set the global sort option to false since that will also sort the field definitions, which impacts the Storyblok UI itself.

Your Graphql file

Basic example:

# For root content types, add the `@storyblok(type: contentType)` directive
type Page @storyblok(type: contentType) {
  # Add a `@storyblokField` directive to add extra configuration for a field such as translations
  seoTitle: String @storyblokField(translatable: true, section: "SEO")
  seoDescription: String @storyblokField(translatable: true, section: "SEO")

  blocks: [Block] @storyblokField
}

union Block = MarkdownBlock | BannerBlock

# By default a type is a nested Storyblok component
type MarkdownBlock @storyblok {
  content: String @storyblokField(format: markdown, translatable: true)
}

type BannerBlock @storyblok(icon: block_image) {
  title: String @storyblokField(translatable: true)
  link: StoryblokLink @storyblokField
  image: StoryblokAsset! @storyblokField(filetypes: [image])
}

type ProductListBlock @storyblok {
  title: String @storyblokField(translatable: true)
}

type Article @storyblok {
  # This field will be ignored
  systemField: String
  date: Date @storyblokField
  author: String @storyblokField
  content: String @storyblokField(format: markdown, translatable: true)
}

Advanced examples

Tabs and Sections

Fields can be grouped into tabs and/or sections with corresponding storyblokField arguments.

type A @storyblok {
  a: String @storyblokField(tab: "my-tab")
  b: String @storyblokField(tab: "my-tab")
  c: String @storyblokField(section: "my-section")
}

Story Option Type

A story option type renders a dropdown list with available stories.

To create an option field with a story reference, create a field that references to contentType or universal.

type A @storyblok {
  story: Story @storyblokField(folder: "{0}/some-folder")
}

type Story @storyblok(type: contentType) {
  name: String @storyblokField
}

Similarly, you'll get an options field if you provide an array. Furthermore, the reference may also be a union type. But if so, all types of the union type must either be a contentType or a universal type.

Your resolvers file

This repository also contains a set of resolvers that can be used to do a couple of things:

  • resolve internal and external links
  • resolve an id field (based on the _uid field)
  • resolve single blok fields
  • resolve rich text as a serialized JSON string
  • resolve union types
  • resolve stories for single and multiple option fields

Usage

import { logger } from '@commerce-backend/observability'
import { mergeResolvers } from '@graphql-tools/merge'
import {
  storyblokResolvers,
  updateContext,
} from 'storyblok-graphql-codegen-terraform/resolvers'
import StoryblokClient from 'storyblok-js-client'
import { typeDefs } from './typedefs.js'

const client = new StoryblokClient({
  accessToken: process.env.STORYBLOK_ACCESS_TOKEN,
})

export const customResolvers = {
  Query: {
    contentPage: (_parent, args, context, _info) =>
      client
        .get(`cdn/stories/pages/${args.path}`, {
          resolve_links: 'url', // this is required for the link resolver to work
          resolve_relations: ['content_page.usps'], // TODO: make this dynamic
        })
        // Use the update context so the resolvers can resolve links and story options
        .then(updateContext(context))
        .then((response) => ({
          ...response.data?.story.content,
          pageId: response.data?.story.id,
        })),
  },
}

const resolvers = mergeResolvers([
  // include all storyblok resolvers
  storyblokResolvers(typeDefs, {
    // optionally modify the relative story paths for the link resolver
    slugResolver: (fullPath) => fullPath.split('/pages/')?.[1] ?? fullPath,
  }),
  // add your own resolvers
  customResolvers,
])

export default resolvers