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

amplience-graphql-codegen-json

v1.2.0

Published

This is a plugin for GraphQL codegen that generates Amplience JSON schemas from your Graphql schema.

Downloads

3,305

Readme

amplience-graphql-codegen-json

This is a plugin for GraphQL codegen that generates Amplience JSON schemas from your Graphql schema.

This plugin will look for Graphql types within your schema that contain an @amplienceContentType directive and generate a JSON schema file for each type.

For more information on the Amplience JSON schemas see the documentation on amplience.com.

A basic example

overwrite: true
hooks:
  afterAllFileWrite:
    - prettier --write
schema: ./schema.graphql
generates:
  terraform/amplience_content_types.tf:
    preset: amplience-graphql-codegen-json
    plugins:
      - amplience-graphql-codegen-json
    config:
      hostname: https://schema-examples.com

The hostname is optional and will default to https://schema-examples.com.

type MyContentType @amplienceContentType {
  """
  This a description for the "name" property.
  """
  name: String
  age: Int!
}

This will generate 1 json schema file named terraform/schemas/my-content-type.json describing the content type with 2 properties of which age is required.

Fields

Besides primitive types, lists and enums, you can also use your custom types. These custom types will be generated as inline types by default. To create content links, use the @link directive as shown below. Alternatively, to create content references, use the @reference directive as shown below. Please keep in mind that linked or referenced types also need an @amplienceContentType directive, otherwise the linked field will link to a nonexisting content type.

Union types are always linked so no @link directive is necessary.

Special Amplience Scalars

This plugin adds 2 basic Amplience Scalars that you can use:

  • AmplienceImage
  • AmplienceVideo
type MyContentType @amplienceContentType {
  image: AmplienceImage!
  video: AmplienceVideo!
}

Field directives

To further enhance the properties in the JSON schemas, you can add directives to the fields.

@amplienceText

Only works on String types.

type MyContentType @amplienceContentType {
  description: String!
    @amplienceText(
      minLength: 2
      maxLength: 4
      format: markdown
      examples: ["fireman", "musician"]
    )
}

@amplienceNumber

Only works on Int and Float types.

type MyContentType @amplienceContentType {
  rating: Int! @amplienceNumber(minimum: 0, maximum: 10)
}

@amplienceList

Only works on list types.

type MyContentType @amplienceContentType {
  name: [String!] @amplienceList(minItems: 1, maxItems: 10)
}

@amplienceLocalized

Works on String, Int, Float, Boolean, AmplienceImage, and AmplienceVideo.

type MyContentType @amplienceContentType {
  name: String! @amplienceLocalized
}

@amplienceLink

Only works on custom types.

type MyContentType @amplienceContentType {
  other: OtherContentType @amplienceLink
}

type OtherContentType @amplienceContentType {
  name: String!
}

@amplienceReference

Only works on custom types.

type MyContentType @amplienceContentType {
  other: OtherContentType @amplienceReference
}

type OtherContentType @amplienceContentType {
  name: String!
}

@amplienceConst

Only works on String! and [String!]! types.

Note that for a string list, you should use the items argument, whereas for a regular string, you should use the item argument.

type MyContentType @amplienceContentType {
  constString: String @amplienceConst(item: "const")
  constArray: [String!]! @amplienceConst(items: ["this", "is", "const"])
}

@amplienceDeliveryKey

Adds a delivery key field to the Content Type form. Only works on String types.

See documentation

type MyContentType @amplienceContentType {
  deliveryKey: String
    @amplienceDeliveryKey(
      # Optional field title
      # Default value: 'Delivery Key'
      title: "example title"

      # Optional field description
      # Default value: 'Set a delivery key for this content item'
      description: "Format: delivery-key/format/requirement"

      # Optional field validation pattern
      pattern: "delivery-key/format/requirement"
    )
}

@amplienceExtension

Currently works ONLY on custom types (object) See available extensions

type MyContentType @amplienceContentType {
  other: OtherContentType
    @amplienceExtension(
      # Name should point to the registered extension name on Amplience
      name: "extension-name"
    )
}

type OtherContentType {
  name: String
}