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

vue-relay

v5.0.2

Published

A framework for building GraphQL-driven Vue.js applications.

Downloads

19

Readme

vue-relay

A framework for building GraphQL-driven Vue.js applications.

npm

Introduction

Installation and Setup

Installation

Install Vue and Relay using yarn or npm:

yarn add vue vue-relay

Set up babel-plugin-relay

Relay Modern requires a Babel plugin to convert GraphQL to runtime artifacts:

yarn add --dev babel-plugin-relay graphql

Add "relay" to the list of plugins your .babelrc file:

{
  "plugins": [
    "relay"
  ]
}

Please note that the "relay" plugin should run before other plugins or presets to ensure the graphql template literals are correctly transformed. See Babel's documentation on this topic.

Set up relay-compiler

Relay's ahead-of-time compilation requires the Relay Compiler, which you can install via yarn or npm:

yarn add --dev relay-compiler graphql

This installs the bin script relay-compiler in your node_modules folder. It's recommended to run this from a yarn/npm script by adding a script to your package.json file:

"scripts": {
  "relay": "relay-compiler --src ./src --schema ./schema.graphql"
}

Then, after making edits to your application files, just run the relay script to generate new compiled artifacts:

yarn run relay

Note: relay-compiler does not understand single-file components with a .vue extension. You can export graphql template literals in .js files, and then import them in .vue single-file components.

For more details, check out Relay Compiler docs.


API Reference

<QueryRenderer />

Props

  • environment: The Relay Environment
  • query: The graphql tagged query. Note: To enable compatibility mode, relay-compiler enforces the query to be named as <FileName>Query. Optional, if not provided, an empty props object is passed to the render callback.
  • variables: Object containing set of variables to pass to the GraphQL query, i.e. a mapping from variable name to value. Note: If a new set of variables is passed, the QueryRenderer will re-fetch the query.

Scoped Slot Props

  • props: Object containing data obtained from the query; the shape of this object will match the shape of the query. If this object is not defined, it means that the data is still being fetched.
  • error: Error will be defined if an error has occurred while fetching the query.
  • retry: Reload the data. It is null if query was not provided.

Example

<!-- Example.vue -->
<template>
  <query-renderer :environment="environment" :query="query" :variables="variables" v-slot="{ props, error, retry }">
    <div v-if="error">{{ error.message }}</div>
    <div v-else-if="props">{{ props.page.name }} is great!</div>
    <div v-else>Loading</div>
  </query-renderer>
</template>

<script>
import { QueryRenderer, graphql } from 'vue-relay'

export default {
  name: 'example',
  components: {
    QueryRenderer
  },
  data () {
    return {
      environment: ..., // https://relay.dev/docs/en/relay-environment.html
      query: graphql`
        query ExampleQuery($pageID: ID!) {
          page(id: $pageID) {
            name
          }
        }
      `,
      variables: {
        pageID: '110798995619330'
      }
    }
  }
}
</script>

Fragment Container

createFragmentContainer([component, ]fragmentSpec)

Props

  • fragments as specified by the fragmentSpec

Component / Scoped Slot Props

{
  relay: {
    environment,
  },
  // Additional props as specified by the fragmentSpec
}

Refetch Container

createRefetchContainer([component, ]fragmentSpec, refetchQuery)

Props

  • fragments as specified by the fragmentSpec

Component / Scoped Slot Props

{
  relay: {
    environment,
    refetch(),
  },
  // Additional props as specified by the fragmentSpec
}

Pagination Container

createPaginationContainer([component, ]fragmentSpec, connectionConfig)

Props

  • fragments as specified by the fragmentSpec

Component / Scoped Slot Props

{
  relay: {
    environment,
    hasMore(),
    isLoading(),
    loadMore(),
    refetchConnection()
  },
  // Additional props as specified by the fragmentSpec
}

Comparison with react-relay

  • QueryRenderer does not take render function.
  • Container creating functions take component as an optional argument.
    • If provided, a conatiner will pass props to the given component.
    • If ommited, a conatiner will pass props to its default scoped slot.

Other APIs

Other APIs are exactly same as Relay's Public APIs. Please refer to Relay's documentation.


Example

The vue-relay-examples repository contains an implementation of TodoMVC. To try it out:

git clone https://github.com/ntkme/vue-relay-examples.git
cd vue-relay-examples/todo
npm install
npm run build
npm start

License

vue-relay is BSD-2-Clause licensed.

Relay is MIT licensed.