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

graphql-cli-load

v0.1.5

Published

GraphQL CLI Data Loading plugin

Downloads

4

Readme

graphql-cli-load

Data import plugin for graphql-cli.

Installation

npm i -g graphql-cli graphql-cli-load

Configuration

Configure the plugin via the .graphqlconfig or command line.

The schema will be obtained from the schemaPath key, you can fetch it via graphql get-schema

All other options such as csv, json, mutation or mapping can be placed in the extensions.load key or provided via commandline.

Here is an example:

.graphqlconfig

{
  "schemaPath": "schema.graphql",
  "includes": [
    "src/**/*.graphql",
    "src/**/*.gql",
  ],
  "extensions": { 
    "load": { // this section is optional
      "csv" : "reviews.txt",
      "mutation": "createReview",
      "mapping": { "text" : "review", "rating" : "stars"}
    }
  }
}

Usage

You can now run:

graphql load

or

graphql load --csv reviews.txt --mutation createReview2 --mapping '{ "text" : "commentary", "rating" : "stars"}'

Using endpoint starwars: http://localhost:7474/graphql/
Using mutation "createReview2".

Done parsing CSV-file /Users/mh/d/js/graphql-cli-load/example/reviews.txt rows: 3
 meta: {"delimiter":"\t","linebreak":"\n","aborted":false,"truncated":false,"cursor":566,"fields":["episode","text","rating"]}

Using mapping: {"text":"commentary","rating":"stars"}

Sending query:
mutation { 
_0 : createReview2 ( episode: NEWHOPE,commentary: "A legendarily expansive and ambitious start to the sci-fi saga, George Lucas opened our eyes to the possibilities of blockbuster filmmaki...

✔ Call succeeded:
{"_0":"Nodes created: 1\nProperties set: 3\nLabels added: 1\n","_1":"Nodes created: 1\nProperties set: 3\nLabels added: 1\n","_2":"Nodes created: 1\nProperties set: 3\nLabels added: 1\n"}...

Options

/usr/local/bin/graphql load [--json] [--csv] [--endpoint] [--mutation] [--mapping] [--delim]

Optionen:
  --help          Hilfe anzeigen                                       [boolean]
  --mapping, -p   name mapping of input to mutation (json)
  --mutation, -m  mutation to call
  --endpoint, -e  endpoint name to use
  --json, -j      json file to load
  --csv, -c       csv file to load
  --delim, -d     delimiter for arrays   

Which will take each line of the csv or json file and call the mutation on the endpoint with the data (optionally mapping columns). Non-absolute files are resolved relative to the directory containing .graphqlconfig.

Test with Neo4j-GraphQL Extension

To test this with the neo4j-graphql extension:

  1. npm install -g neo4j-graphql-cli
  2. git clone https://github.com/neo4j-graphql/graphql-cli-load && cd example
  3. neo4j-graphql example-schema.graphql (remember the auth header)
  4. npm install -g graphql-cli graphql-cli-load
  5. Run graphql to install the endpoint, and manually add the auth-header to .graphqlconfig, like here:
"endpoints": {
  "starwars": {"url":"http://localhost:7474/graphql/","headers":{"Authorization": "Basic bmVvNGo6dGVzdA=="}}
},
  1. Run graphql load --csv reviews.txt or graphql load --csv reviews.json