Git Product home page Git Product logo

graphql-cli-load's Introduction

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

graphql-cli-load's People

Contributors

jexp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graphql-cli-load's Issues

Gave it a (unsuccessful) try

macOS Sierra

Node 9.

i ran graphql init and to get .graphqlconfig:

$ graphql init
? Local schema file path: schema.graphql
? Endpoint URL (Enter to skip): https://api.graph.cool/relay
/v1/cj9o4se940gsu0148s5a4helr
? Name of this endpoint, for e.g. default, dev, prod: server


? Subscription URL (Enter to skip):
? Do you want to add other endpoints? No
? What format do you want to save your config in? JSON

About to write to /Users/shingdev/code/GRAPHCOOL/react-graphql/quickstart-with-relay-modern/.graphqlconfig:

{
  "schemaPath": "schema.graphql",
  "extensions": {
    "endpoints": {
      "server": "https://api.graph.cool/relay/v1/cj9o4se940gsu0148s5a4helr"
    }
  }
}

? Is this ok? Yes```

then ran graphql get-schema, which saw no changes with the previously existing schema.graphql file which seemed correct.

$ graphql get-schema
Downloading introspection from https://api.graph.cool/relay/v1/cj9o4se940gsu0148s5a4helr
No changes


I then ran graphql load which failed with this json file [https://gist.github.com/idkjs/06d10b7a02edb8e6a2b10cb4608bdaa4] :

$ graphql load -m createCompany --json companies.json
Using endpoint server: undefined
Using mutation "createCompany": "".
Done parsing JSON-file /Users/shingdev/code/GRAPHCOOL/react-graphql/quickstart-with-relay-modern/companies.json rows: 90
Sending query:
mutation {

}...

Parameter "url" must be a string, not undefined

I changed the endpoint in graphconfig to this:


{
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"server": {"url":"https://api.graph.cool/relay/v1/cj9o4se940gsu0148s5a4helr"}
}
}
}


Which produced this error:

```sh
GraphQL Error (Code: 200): {"response":{"error":"Syntax error while parsing GraphQL query. Invalid input \"mutation { \\n\\n}\", expected OperationDefinition, FragmentDefinition or TypeSystemDefinition (line 1, column 1):\nmutation { \n^","status":200},"request":{"query":"mutation { \n\n}","variables":{}}}

This is my graphcool playground mutation def:

screen shot 2017-11-06 at 13 51 14

This is what the mutation looks like in DevTools if I do one manually

-mutation & variables

mutation CreateCompanyMutation(
  $input: CreateCompanyInput!
) {
  createCompany(input: $input) {
    company {
      id
      description
      logo
    }
  }
}
  • variables
{
    "input": {
        "description": "testatt",
        "logo": "https://d25e16a427ed3ce77d27-76b466cd72f6b3a6e7219a8a02851d8e.ssl.cf1.rackcdn.com/files/59382428ff3935425ca91516/size_5_1001pharmaciesjpg.jpg",
        "clientMutationId": ""
    }
}

Any ideas? Thank you.

Syntax Error: Expected Name, found }

Hello jexp, first thanks for the project, it looks very useful.

I'm having a problem when running the grapqhl load that maybe you would know what it would mean.

Using endpoint local: {"url":"http://localhost:4000"}
Using mutation "post": "".
Done parsing CSV-file /Users/Me/Desktop/devtest/hackernews-node/reviews.txt rows: 3
 meta: {"delimiter":"\t","linebreak":"\n","aborted":false,"truncated":false,"cursor":571,"fields":["episode","commentary","stars"]}
Using mapping: {"description":"commentary","url":"stars"}
Sending query:
mutation { 

}...
✖ 
Syntax Error: Expected Name, found }: {"response":{"errors":[{"message":"Syntax Error: Expected Name, found }","locations":[{"line":3,"column":1}]}],"status":400},"request":{"query":"mutation { \n\n}","variables":{}}}

I'm running the database API with prisma, and I have uploaded my whole minimum viable test project to get this functionality working in this repository: https://github.com/daquintero/testGraphqlCLILoad/tree/master

I'm not sure if this is enough information for the question, but please tell me if you need anything else. I appreciate very much the help!

Loading json data

I'm trying to load data from a json file, when executing the graphql load command I get the following complains:

Sending query: mutation { _0 : createBlabla ( blabla1: 123,blabla2: "blabla2", blabla3: "blabla3 ) { blabla } _1 : ... }... Field "blabla" of type "BlablaType" must have a sub selection.:

If I execute the same mutation from that output in graphql, blabla will expand to blabla { id } and data is successfully added.

P.S. I got the server schema via graphql get-schema

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.