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

content-graphql

v1.0.7

Published

Generates an executable graphql schema from a list of masks.

Downloads

7

Readme

content-graphql

Generates an executable graphql schema from a list of masks.

Usage

npm install content-graphql graphql --save
const pg = require("content-graphql");
const { graphql } = require("graphql");

// create a prismic repository with a mask named `Page`
const masks = {
  Page: {
    Main: {
      uid: {
        type: "UID",
        config: {
          label: "slug"
        }
      }
    }
  }
};
const schema = pg(masks);

const query = `{
    searchOne{
        uid
    }
}`;

graphql(schema, query, null, {
  repository: "your_repository_name"
}).then(response => {
  console.log(response);
  // { data: { searchOne: { uid: 'ezf' } } }
});

Api

pg(masks, {

  contentUrl: (context, ref) => {
    // this function allows you overwrite the url to query data
    return `http://a-json-endpoint-somewhere-with-content`;
  },

  contentRefUrl: (context) => {
    // this function allows you overwrite the url to find the current ref
    return `http://a-json-endpoint-somewhere-with-the-ref-data`;
  },

  // [OPTIONAL]
  transform: (doc, context) => {
    // this function will run before returning a document
    // it lets you transform the prismic document before it is processed by graphql
    return doSomething(doc);
  },

  // [OPTIONAL]
  transformTextField: (field, context) => {
    // This function will be called on textual fields. `Text` or `StructuredText`
    return doSomething(field);
  },

  // [OPTIONAL]
  linkResolver: doc => {
    if (doc.type === "article") return `/article/${doc.uid}`;
    return "/";
  }


  // [OPTIONAL]
  typeResolver: doc => {
    // lets you use the same graphql type for multiple masks
    if (doc.type === "employer-article") return `article`;
    if (doc.type === "employee-article") return `article`;
    if (doc.type === "admin-article") return `article`;
    return "/";
  }
});

Debug

Setting the environment variable CONTENT_GRAPHQL_DEBUG=true will log queries that are actually sent to prismic.

Assumptions

- slice names must be globaly unique across masks. (A global Slice interface is declared)

Structured Text

StructuredText will be transformed to HTML using PrismicDOM.RichText.asHtml.

Link Resolving

Link resolving can be done server side by providing the optional linkResolver option.

TODO

[] add more tests
[] handle image sizes

Changelog

1.0.6

  • add DEBUG_CONTENT_GRAPHQL env variable to enable logging

1.0.5

  • add CONTENT_GRAPHQL_API_CACHE env variable

1.0.4

  • fix language issue with local file content

1.0.3

  • fix cache issue
  • fix lang query issue

1.0.2

  • only cache ref for 5 seconds in production mode

1.0.1

All queries are now resolved by filtering a single json document instead af sending all queries to prismic.

  • removed query argument from search and searchOne
  • added type argument to search and searchOne.
  • added uid argument to search and searchOne

BREAKING CHANGE

# before
search(query: "[[:d = at(my.document.type, \"article\")]]) {
  title
}

# after
search(type: "article") {
  title
}



# before
search(query: "[[:d = at(my.article.uid, \"my-artcile\")]]) {
  title
}

# after
search(type: "article", uid: "article") {
  title
}

0.0.19

  • add ability to assign multiple masks to the same graphqltype see typeResolver feature
  • add searchOneAsType

0.0.18

  • add id

0.0.17

  • fix missing url field on root values (was only working with Link fields)

0.0.16

  • handle null values in link

0.0.14

  • change preTransform for transformTextField
  • allow link resolving serverside
  • render structured text server side

0.0.13

  • fix overfetching issue
  • preTransform function
  • add debug env

0.0.11

fix issue with linked documents

0.0.11

fix issue with linked documents

0.0.10

fix another transform bug

0.0.9

transform bug fix

0.0.8

transform

0.0.7

Language support

0.0.6

Handle masks with "-"

0.0.5

handle unknown slices

0.0.4

handle lower case mask names

0.0.1

initial version