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

@teip/wald

v0.2.0

Published

GraphQL dependency engine

Downloads

3

Readme

Wald - A GraphQL dependency resolution engine

Wald enables a special import syntax for graphql files and offers a simple dependency resolving algorithm.

#import { MyFragment } from './myFragment.graphql'

query HelloWorld {
  hello {
    ...MyFragment
  }
}

Introduction

Wald enables you to import fragments from other graphql files into your qraphql file. Wald then parses the files and creates a Wald file tree structure similar to the DocumentNode from graphql-js but with support for imports. It will then recursively resolve all files that are referenced and fill a map that maps the file path to the Wald file info object. If you just want to use the capabilities that Wald provides, this is probably the wrong package for you. Instead you can use the existing solutions that depend on this package. For webpack use @teip/loader. For creating flow types and everything else the Teip framework offers use @teip/cli.

Wald also comes with some utility functions that help out with working on a PathMap. For more on that read the usage section.

This package is used internally within the Teip framework. Let me know about your ideas especially if you are using it elsewhere.

Usage

For this we will assume the following file structure:

src
 |- myFragment.graphql
 '- myQuery.graphql (import { MyFragment } from './myFragment.graphql')

Lets assume you are interested in a specific GraphQL definition file. You can use resolveFile to asynchronously resolve the content of a file and receive the WaldFile representation of the file. This representation contains the definitions just like you are used from DocumentNode from graphql-js. It also contains the file name and all the imports of the file.

const file = await resolveFile('./myQuery.graphql');
/* {
     filePath: './myQuery.graphql',
     imports: [{ filePath: './myFragment.graphql', name: 'MyFragment' }],
     definitions: [{ kind: 'OperationDefinition', ... }],
   } */

When you are now working with the file, e.g. going through a selection, you come across fragment references. Since Wald enables importing fragment definitions the definition can either be found in the file itself (definitions) or in the imports. If the definition is in the imports the imported file has to be resolved as well and the definition might then be found in the imported file. This definition again can have references to other files and they will all have to be recursively resolved. To make this a bit easier and more efficient Wald comes with the idea of a PathMap. A path map contains all the WaldFile results for all the files that are required.

const pathMap = await fillMap('./myQuery.graphql');
/* Map {
     './myQuery.graphql' => { ... },
     './myFragment.graphql' => { ... },
   } */

// Can be resolved within the query file since it is imported here
const fragment = resolveFragmentName(pathMap, 'MyFragment', './myQuery.graphql');

// Or directly in the file where it is defined
fragment === resolveFragmentName(pathMap, 'MyFragment', './myFragment.graphql');

This way the dependencies can all be resolved at once and afterwards quick synchronous lookups are possible.

It is also possible to resolve any kind of definition using the more general resolveName. Both functions will throw if the name cannot be resolved but resolveFragmentName will also throw when the name can be resolved but the found definition is not a fragment definition.