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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sanity-graphql-schema

v0.0.7

Published

Declare a Sanity schema using GraphQL SDL syntax

Downloads

10

Readme

sanity-graphql-schema

Declare a Sanity schema using GraphQL SDL syntax. Try the demo?

  • Auto-infers title from type/field names (leadAsset -> Lead asset)
  • Type names are automatically camelcased (BlogPost -> blogPost)
  • Types that implement "Document" is made into document types
  • Document types as field type assumed to be references, object types as inline
    • Use @inline directive to use document type embedded into parent document
  • Directives for most schema type options
  • "Non null" treated as "required" validation rule (only enforced in Studio)

Installation

# In your Sanity studio folder
yarn add sanity-graphql-schema

Basic usage

In your schema entry point (usually schemas/schema.js), you normally have something along the lines of this:

import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'

import author from './author'

export default createSchema({
  name: 'default',
  types: schemaTypes.concat([author])
})

To use this module, import it, call the imported function with a GraphQL schema defined in the GraphQL schema definition language, and replace the value passed to createSchema() with the output:

import createSchema from 'part:@sanity/base/schema-creator'
import {fromGQL, graphql} from 'sanity-graphql-schema'

const schema = graphql`
  type Author implements Document {
    name: String!
    profileImage: Image
  }

  type BlogPost implements Document {
    title: String!
    slug: Slug
    body: Text
    leadImage: CaptionedImage
    tags: [String!]! @display(layout: "tags")
    author: Author!
  }

  type CaptionedImage implements Image {
    caption: String!
  }
`

export default createSchema({
  name: 'default',
  types: fromGQL(schema)
})

Directives

  • @display(title: String, icon: String, layout: String) Allows you to:
    • Set title of fields and types, overriding the auto-generated title
    • Set layout mode for a field (for instance, set tags as layout for an array field)
    • Set icon for document types by passing an icon ID (see example below)
  • @fieldsets(from: [SanitySchemaFieldSet!]!) Set the fieldsets available for an object/document type. Takes an array of {name, title} pairs

  • @fieldset(set: String!) Assign a field to a given fieldset

  • @orderings(from: [SanitySchemaOrdering!]!) Set the available ordering options for a document type. Takes an array of {name, title, by} pairs - see Sanity documentation for more information

  • @enum(values: [SanityNameTitlePair!]!, layout: String, direction: String) Set on string fields if you only want to allow certain values.
    • values takes an array of {name, title} pairs.
    • layout can be one of dropdown or radio, dropdown being the default.
    • direction determines which way radio buttons flow (horizontal, vertical)
  • @extract(metadata: [String!]!, originalFilename: Boolean) Set on fields of type Image or File to determine which metadata to extract, and whether or not to store the original filename

  • @slug(source: String, maxLength: Int) Set on fields of type Slug, determines which field to generate slugs from, or set maximum length of the slug.

  • @hotspot Set on image fields to opt-in to the hotspot/crop functionality

  • @inline Set on fields that use a document type as it's value if you want to embed the value instead of referencing an existing document

  • @hidden Set on fields to hide them from the user interface, yet still be recognized by the underlying schema machinery

  • @readOnly Set on fields to that should not be editable from the studio

Todo

  • [x] Generate GQL types for custom types (color input, for instance)
  • [x] Custom scalars (markdown)
  • [x] Throw on non-reference union fields
  • [x] Better error handling
  • [x] Blocks/spans
  • [ ] Validation directives
  • [ ] Inject icons, input components as options argument
  • [ ] JSON scalar for arbitrary input for custom types? Or options as dotpath? Both?

Developing

git clone [email protected]:rexxars/sanity-graphql-schema.git
cd sanity-graphql-schema
npm install
npm test

License

MIT © Espen Hovlandsdal