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

core-types-graphql

v3.0.0

Published

core-types ⬌ GraphQL conversion

Downloads

65,935

Readme

npm version downloads build status coverage status Node.JS version

core-types-graphql

This package provides conversion functions between core-types and GraphQL.

You probably don't want to use this package directly, but rather typeconv which uses this package to convert between TypeScript, JSON Schema and GraphQL.

Other conversion packages:

Versions

Since 3.0, this package is pure ESM and requires Node 14.13.1 or later.

Contents

Usage

There are two conversion functions, convertCoreTypesToGraphql and convertGraphqlToCoreTypes, both returning a wrapped value, of the type ConversionResult.

core-types to GraphQL

Conversion can be done to GraphQL code using convertCoreTypesToGraphql, but also to GraphQL AST using convertCoreTypesToGraphqlAst. The arguments to these are the same.

import { convertCoreTypesToGraphql } from 'core-types-graphql'

let doc; // This core-types document comes from somewhere

const { data: graphQL } = convertCoreTypesToGraphql( doc );

You can provide options as a second argument fn the type:

interface CoreTypesToGraphqlOptions
{
	warn?: WarnFunction;
	filename?: string;
	sourceFilename?: string;
	userPackage?: string;
	userPackageUrl?: string;
	nullTypeName?: string | null;
	nameGenerator?: NameGeneratorFunction;
	unsupported?: 'ignore' | 'warn' | 'error';
	includeComment?: boolean;
}

These options are all optional.

  • warn: A function callback to be used for warnings, defaults to console.warn.
  • filename The filename to be written to.This is a hint, no file will be written by the conversion function.
  • sourceFilename: The name of the source file from which the core-types comes.
  • userPackage: The name of the package using this package.
  • userPackageUrl: The url to the package using this package.
  • nullTypeName: Optional custom type used for null.
  • nameGenerator: A function for generating names.GraphQL doesn't support inline objects or union types,so these must be constructed as separate types.
  • unsupported: What to do when detecting an unsupported type
    • ignore: Ignore (skip) type
    • warn: Ignore type, but warn (default)
    • error: Throw an error
  • includeComment: Includes a header comment about the auto-generated file.Defaults to true.

The warn function is of type WarnFunction from core-types, meaning it takes a message as string, and an optional second argument of type CoreTypesErrorMeta, also from core-types.

The nameGenerator function is of type NameGeneratorFunction defined as:

( baseName: string, nameHint: string, test: NameGeneratorTestFunction ) => string;

where NameGeneratorTestFunction is a test function to check if the generated name is available, on the form:

( name: string ) => boolean;

If this is specified (instead of letting a default name generator be used), an implementation is supposed to generate a name, potentially based on the baseName and a nameHint (e.g. an interface name and a property name within that interface), and test this generated name against test, altering it if necessary until test returns true, and then return that string.

GraphQL to core-types

import { convertGraphqlToCoreTypes } from 'core-types-graphql'

let graphQL; // This GraphQL string comes from somewhere

const { data: doc } = convertGraphqlToCoreTypes( graphQL );

An optional second argument can be provided on the form

interface GraphqlToCoreTypesOptions
{
	warn?: WarnFunction;
	unsupported?: 'ignore' | 'warn' | 'error';
}
  • warn: The same warn function as in CoreTypesToGraphqlOptions
  • unsupported: What to do when detecting an unsupported type
    • ignore: Ignore (skip) type (default)
    • warn: Ignore type, but warn
    • error: Throw an error

Utilities

This package exports two utility functions; getBreakingChanges and getDangerousChanges which both take two GraphQL source code texts (as strings) semantically meaning an "old" and a "new" version of a schema. The functions return a list of breaking/dangerous changes on the type BreakingChange/DangerousChange from the graphql package.