|
| 1 | +# graphql-cli-load |
| 2 | + |
| 3 | +Data import plugin for graphql-cli. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +``` |
| 8 | +npm i -g graphql-cli graphql-cli-load |
| 9 | +``` |
| 10 | + |
| 11 | +## Configuration |
| 12 | + |
| 13 | +Configure the plugin via the `.graphqlconfig` or command line. |
| 14 | + |
| 15 | +The schema will be obtained from the `schemaPath` key, you can fetch it via `graphql get-schema` |
| 16 | + |
| 17 | +All other options such as `csv`, `json`, `mutation` or `mapping` _can_ be placed in the `extensions.load` key |
| 18 | +or provided via commandline. |
| 19 | + |
| 20 | +Here is an example: |
| 21 | + |
| 22 | +`.graphqlconfig` |
| 23 | +```json |
| 24 | +{ |
| 25 | + "schemaPath": "schema.graphql", |
| 26 | + "includes": [ |
| 27 | + "src/**/*.graphql", |
| 28 | + "src/**/*.gql", |
| 29 | + ], |
| 30 | + "extensions": { |
| 31 | + "load": { // this section is optional |
| 32 | + "csv" : "reviews.txt", |
| 33 | + "mutation": "createReview", |
| 34 | + "mapping": { "text" : "review", "rating" : "stars"} |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +You can now run: |
| 43 | + |
| 44 | +``` |
| 45 | +graphql load |
| 46 | +``` |
| 47 | + |
| 48 | +or |
| 49 | + |
| 50 | +``` |
| 51 | +graphql load --csv reviews.txt --mutation createReview2 --mapping '{ "text" : "commentary", "rating" : "stars"}' |
| 52 | +
|
| 53 | +Using endpoint starwars: http://localhost:7474/graphql/ |
| 54 | +Using mutation "createReview2". |
| 55 | +
|
| 56 | +Done parsing CSV-file /Users/mh/d/js/graphql-cli-load/example/reviews.txt rows: 3 |
| 57 | + meta: {"delimiter":"\t","linebreak":"\n","aborted":false,"truncated":false,"cursor":566,"fields":["episode","text","rating"]} |
| 58 | +
|
| 59 | +Using mapping: {"text":"commentary","rating":"stars"} |
| 60 | +
|
| 61 | +Sending query: |
| 62 | +mutation { |
| 63 | +_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... |
| 64 | +
|
| 65 | +✔ Call succeeded: |
| 66 | +{"_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"}... |
| 67 | +``` |
| 68 | + |
| 69 | +## Options |
| 70 | + |
| 71 | +``` |
| 72 | +graphql load [--json=file.json] [--csv=file.csv] [--endpoint=name] [--mutation=createType] [--mapping='{"title":"name"}'] |
| 73 | +
|
| 74 | +Optionen: |
| 75 | + --help show help |
| 76 | + --mapping, -p name mapping of input to mutation (json) |
| 77 | + --mutation, -m mutation to call |
| 78 | + --endpoint, -e endpoint name to use |
| 79 | + --json, -j json file to load |
| 80 | + --csv, -c csv file to load |
| 81 | +``` |
| 82 | + |
| 83 | +Which will take each line of the csv or json file and call the mutation with the data (optionally mapping columns). |
| 84 | +Non-absolute files are resolved relative to the directory containing `.graphqlconfig`. |
| 85 | + |
| 86 | +## TODO |
| 87 | + |
| 88 | +* parameters |
| 89 | +* type conversion |
| 90 | +* file urls |
| 91 | + |
| 92 | + |
| 93 | +## Test with Neo4j-GraphQL Extension |
| 94 | + |
| 95 | +To test this with the neo4j-graphql extension: |
| 96 | + |
| 97 | +1. `npm install -g neo4j-graphql-cli` |
| 98 | +2. `neo4j-graphql example/example-schema.graphql` (remember the auth header) |
| 99 | +4. `npm install -g graphql-cli graphql-cli-load` |
| 100 | +5. Run `graphql` in `example` to install the endpoint, and manually add the auth-header, like here: |
| 101 | +``` |
| 102 | +"endpoints": { |
| 103 | + "starwars": {"url":"http://localhost:7474/graphql/","headers":{"Authorization": "Basic bmVvNGo6dGVzdA=="}} |
| 104 | +}, |
| 105 | +``` |
| 106 | +6. Run `graphql load --csv reviews2.txt` or `graphql load --csv reviews2.json` |
0 commit comments