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

inversify-graphql

v1.2.3

Published

Builds dependency-inverted GraphQL schemas with InversifyJS

Downloads

572

Readme

inversify-graphql

build status npm version Dependencies img img Known Vulnerabilities

Build dependency-inverted GraphQL schemas with InversifyJS

Quickstart

See:

Usage

Install the package

npm i inversify reflect-metadata graphql inversify-graphql --save

Example using express and apollo-server

import { inversifySchema } from 'inversify-graphql';
/* ... initialize express & inversify container */
const srv = new agql.ApolloServer({
    // build inversified schema
    context: /* whateverContext */,
    schema: inversifySchema(myContainer, {
      query: MyRootQuery,
  }),
});
srv.applyMiddleware({ app, path: '/graphql'});

// === MyRootQuery definition ==
export class MyRootQuery extends InversifyObjectTypeBuilder<void, MyContext> {

    // Injected dependency, usable in our resolve() function
    @inject(MyDependency) dependency: MyDependency;

    config(): InversifyObjectConfig<void, MyContext> {
        return {
            name: 'MyRoot',
            // nb: "fields" supports 'partial roots', enabling you to describe one object in multiple separate builders
            //  fields: [PartialRoot1, PartialRoot2],
            fields: {
              // compatible with classic GraphQL objects/types
              classicField: {
                  type: GraphQLString,
                  resolve: () => 'classic'
              },
              // use your "type builders" to refernece inversified field types
              inversifiedField: {
                type: MyType,
                resolve: () => this.dependency.getWhateverEntity()
              },
              // use InversifiedList to build a GraphQLList of an inversified type.
              inversifiedListField: {
                type: InversifyList(MyType),
                resolve: () => this.dependency.getWhateverList()
              }
            }
        }
    }
}
// === MyType definition ==
export class MyType extends InversifyObjectTypeBuilder<MyEntity, MyContext> {

    // Injected dependency, usable in our resolve() function
    @inject(MyDependency) dependency: MyDependency;

    config(): InversifyObjectConfig<MyEntity, MyContext> {
      return {
        //  ... sub fields, using source, context AND inversified dependencies (injectable in this class)
      }
    }
}

Simple inline type definition

You can define sub-types "inline" (cleaner syntax)

export class MyType extends InversifyObjectTypeBuilder<MyEntity, MyContext> {

    // Injected dependency, usable in our resolve() function
    @inject(MyDependency) dependency: MyDependency;

    config(): InversifyObjectConfig<MyEntity, MyContext> {
      return {
        myField: {
          // resolver
          resolve: () => 42,
          // inline type definition
          type: {
            name: 'MyInlineType',
            fields: {
              subField: {
                type: GraphQLString,
                resolve: x => x + 'is the answer', // will output "42 is the answer"
              }
            }
          }
        }
      }
    }
}

Handy shortcuts

If like me, you're annoyed with those very long names like new GraphQLList(new GraphQLNonNull(GraphQLString))), you can use the inversify-graphql/shortcuts helpers to turn them into GList(NN(GString)).

nb: shortcuts are compatible with inversified types ;)

Modular schema definiton

Some type definitions can tend to be bloated as your app grows. In these cases, you might want to split the definition of types in several files or parts of your application.

This is the purpose of "extensible schema", which builds on top of inversify-graphql to enable you to define a more modular schema.


const adminSchema = extensibleSchema('RootName', container);

// those two partial roots will be merged in the schema root
adminSchema.query.merge(PartialRoot1);
adminSchema.query.merge(PartialRoot2);
adminSchema.mutation.merge(PartialMutationRoot2);

// extend a type
// the type 'MyTypeToExtend' will augmented with all the fields defined in MyPartialMap
// nb: this will work even if 'MyTypeToExtend' has not been defined yet
adminSchema.get('MyTypeToExtend').merge(MyPartialMap);

// you can concatenate two schemas:
// this will augment the root of "adminSchema" with everything defined in "userSchma"
adminSchema.concat(userSchma);