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

relay-runtime-query

v0.7.1

Published

Compile your Relay GraphQL queries at runtime, no need for Babel. Only for use in development.

Downloads

41

Readme

relay-runtime-query

Run Relay without transpiling all of your queries ahead of time.

npm install relay-runtime-query

Usage

Initialize a template string transformer function from a GraphQL server URL. In the callback, you will have a function that can transform arbitrary GraphQL queries according to your server schema.

import { initTemplateStringTransformerFromUrl } from 'relay-runtime-query'

initTemplateStringTransformerFromUrl('/graphql', (func) => {
  Relay.QL = func;

  ReactDOM.render(
    <Relay.RootContainer
      Component={App}
      route={new AppHomeRoute()}
    />,
    document.getElementById('root')
  );
});

Alternatively, you can fetch the introspection query yourself and call initTemplateStringTransformer directly:

graphQLFetcher(url, { query: introspectionQuery }).then(result => {
  const schemaJson = result.data;
  Relay.QL = initTemplateStringTransformer(schemaJson));
});

Example

Check out the example app. It is built with the Meteor 1.3 beta build tool, and doesn't include the Relay babel plugin at all. You can easily change your server or client code at will, and the right parts of the app will rebuild. No need to run any build scripts manually after you change your schema.

Why?

It can sometimes be inconvenient that you need a specific babel plugin to compile Relay.QL template strings at build time. Specifically, you need to:

  1. Compile your server
  2. Run the introspection query and save the result to a file
  3. Pass that result into a Babel 6 plugin to compile your client code
  4. Run your client

This has several consequences, in particular:

  1. You absolutely need to use Babel 6
  2. You can't easily develop the client and server in parallel (if one person is working on both) because of the multitude of compilation steps above
  3. You can't play around with queries in the browser console since they won't be compiled so that Relay will understand them

With this package, you can avoid all the drawbacks above when developing your app by compiling your queries at runtime.

Caveats

At this stage, the package is more of a proof of concept, but I expect it will greatly help me with my exploration of Relay. Perhaps it will help you too, and perhaps you can help me improve the implementation!

  1. This should only be used in development and testing, since it will no doubt slow down your application. I'd suggest using the actual babel-relay-plugin when deploying a real app to production.
  2. Sane error handling has not yet been implemented. It should be pretty simple to add nice error support for schema validation, so you still get many of the benefits of pre-compiling your schema.