graphql-cli-load icon indicating copy to clipboard operation
graphql-cli-load copied to clipboard

Syntax Error: Expected Name, found }

Open daquintero opened this issue 7 years ago • 6 comments

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!

daquintero avatar Sep 07 '18 20:09 daquintero

I've found https://github.com/prisma/prisma/issues/1981 but I'm not sure its relationship given that in the graphql playground localhost:4000 the mutation works correctly, but through the graphql-cli-load I get this error.

daquintero avatar Sep 08 '18 02:09 daquintero

Solved it, the mappings inside the const column=(rMapping[key]||key).toString(); were not giving me the correct column headers for the values generation that is used in the mappings, so I changed it to const column = mapping[key].toString() which gave me the correct mappings when using this output:

$  graphql load --csv reviews.txt --mutation corruptionIn --mapping '{ "url" : "commentary", "description" : "stars", "postedBy": "episode"}'

**Output:**
Graphql-load has been invoked
Invalid project name specified
? Select a project: app
Using endpoint default: {"url":"http://localhost:4000","headers":{"Authorization":"Bearer "}}
At getSchema the config parameter is: {"config":{"schemaPath":"src/schema.graphql","extensions":{"endpoints":{"default":{"url":"http://localhost:4000","headers":{"Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjamxzZWEycW5maTlyMGI1MnhlY3N5Z2pxIiwiaWF0IjoxNTM2MzQ4NTg0fQ.viWKO-M7we69yGPmIh82jq0dDxRzPfYTMNHsuZrVzhk"}}}}},"configPath":"/Users/darioquintero/Desktop/devVotoInformado/hackernews-node/.graphqlconfig.yml","projectName":"app"}
Using mutation "corruptionIn": "".
Done parsing CSV-file /Users/darioquintero/Desktop/devVotoInformado/hackernews-node/reviews.txt rows: 3
 meta: {"delimiter":"\t","linebreak":"\n","aborted":false,"truncated":false,"cursor":571,"fields":["episode","commentary","stars"]}
Using mapping: {"url":"commentary","description":"stars","postedBy":"episode"}
While mapping is {"url":"commentary","description":"stars","postedBy":"episode"} , but rMapping is {"commentary":"url","stars":"description","episode":"postedBy"}

 row when it was declared is: {"episode":"NEWHOPE","commentary":"A legendarily expansive and ambitious start to the sci-fi saga, George Lucas opened our eyes to the possibilities of blockbuster filmmaking and things have never been the same.","stars":"93"}
Correcting the key mapping data with const column =  mapping[key].toString() is commentary

 At data.map in buildMutations key is: url and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: commentary
return arg.nameurl : value "A legendarily expansive and ambitious start to the sci-fi saga, George Lucas opened our eyes to the possibilities of blockbuster filmmaking and things have never been the same." in data.map at buildMutations
Correcting the key mapping data with const column =  mapping[key].toString() is stars

 At data.map in buildMutations key is: description and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: stars
return arg.namedescription : value "93" in data.map at buildMutations
Correcting the key mapping data with const column =  mapping[key].toString() is episode

 At data.map in buildMutations key is: postedBy and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: episode
return arg.namepostedBy : value "NEWHOPE" in data.map at buildMutations

 returnExpression at data.map at buildMutations returns: { id }

 row when it was declared is: {"episode":"EMPIRE","commentary":"Dark, sinister, but ultimately even more involving than A New Hope, The Empire Strikes Back defies viewer expectations and takes the series to heightened emotional levels.","stars":"94"}
Correcting the key mapping data with const column =  mapping[key].toString() is commentary

 At data.map in buildMutations key is: url and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: commentary
return arg.nameurl : value "Dark, sinister, but ultimately even more involving than A New Hope, The Empire Strikes Back defies viewer expectations and takes the series to heightened emotional levels." in data.map at buildMutations
Correcting the key mapping data with const column =  mapping[key].toString() is stars

 At data.map in buildMutations key is: description and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: stars
return arg.namedescription : value "94" in data.map at buildMutations
Correcting the key mapping data with const column =  mapping[key].toString() is episode

 At data.map in buildMutations key is: postedBy and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: episode
return arg.namepostedBy : value "EMPIRE" in data.map at buildMutations

 returnExpression at data.map at buildMutations returns: { id }

 row when it was declared is: {"episode":"JEDI","commentary":"Though failing to reach the cinematic heights of its predecessors, Return of the Jedi remains an entertaining sci-fi adventure and a fitting end to the classic trilogy.","stars":"80"}
Correcting the key mapping data with const column =  mapping[key].toString() is commentary

 At data.map in buildMutations key is: url and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: commentary
return arg.nameurl : value "Though failing to reach the cinematic heights of its predecessors, Return of the Jedi remains an entertaining sci-fi adventure and a fitting end to the classic trilogy." in data.map at buildMutations
Correcting the key mapping data with const column =  mapping[key].toString() is stars

 At data.map in buildMutations key is: description and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: stars
return arg.namedescription : value "80" in data.map at buildMutations
Correcting the key mapping data with const column =  mapping[key].toString() is episode

 At data.map in buildMutations key is: postedBy and rMapping is: {"commentary":"url","stars":"description","episode":"postedBy"}
When naming the values, we use row[column] where column is: episode
return arg.namepostedBy : value "JEDI" in data.map at buildMutations

 returnExpression at data.map at buildMutations returns: { id }

 buildMutations returns: _0 : corruptionIn ( url: "A legendarily expansive and ambitious start to the sci-fi saga, George Lucas opened our eyes to the possibilities of blockbuster filmmaking and things have never been the same.",description: "93",postedBy: "NEWHOPE" ) { id }
_1 : corruptionIn ( url: "Dark, sinister, but ultimately even more involving than A New Hope, The Empire Strikes Back defies viewer expectations and takes the series to heightened emotional levels.",description: "94",postedBy: "EMPIRE" ) { id }
_2 : corruptionIn ( url: "Though failing to reach the cinematic heights of its predecessors, Return of the Jedi remains an entertaining sci-fi adventure and a fitting end to the classic trilogy.",description: "80",postedBy: "JEDI" ) { id }
mutations at mainWorkflow is mutation { 
_0 : corruptionIn ( url: "A legendarily expansive and ambitious start to the sci-fi saga, George Lucas opened our eyes to the possibilities of blockbuster filmmaking and things have never been the same.",description: "93",postedBy: "NEWHOPE" ) { id }
_1 : corruptionIn ( url: "Dark, sinister, but ultimately even more involving than A New Hope, The Empire Strikes Back defies viewer expectations and takes the series to heightened emotional levels.",description: "94",postedBy: "EMPIRE" ) { id }
_2 : corruptionIn ( url: "Though failing to reach the cinematic heights of its predecessors, Return of the Jedi remains an entertaining sci-fi adventure and a fitting end to the classic trilogy.",description: "80",postedBy: "JEDI" ) { id }
}
Let's see if the error is mutation { 
_0 : corruptionIn ( url: "A legendarily expansive and ambitious start to the sci-fi saga, George Lucas opened our eyes to the possibilities of blockbuster filmmaking and things have never 
Sending query:
mutation { 
_0 : corruptionIn ( url: "A legendarily expansive and ambitious start to the sci-fi saga, George Lucas opened our eyes to the possibilities of blockbuster filmmaking and things have never ...
✔ Call succeeded:
{"_0":{"id":"cjlvgigbdmpj30b52w2bhh2mf"},"_1":{"id":"cjlvgigpkmpj60b52wind3yth"},"_2":{"id":"cjlvgih7ompj90b52or5jdbug"}}...

I will send a pull request for this correction and if you want we can use my repository as the minimum viable graphql-cli-load example code that currently does not exist in a "plug in -and - run" sort of thing.

daquintero avatar Sep 09 '18 22:09 daquintero

I also removed the original example repository since I have now copied the working version of the minimum example code as a separate branch of my own fork here

daquintero avatar Sep 10 '18 03:09 daquintero

Sounds great, thanks so much ! sorry was away over the weekend so I didn't see your initial issue immediately.

jexp avatar Sep 10 '18 06:09 jexp

Your original issue looked like a missing/incorrect mutation name?

jexp avatar Sep 10 '18 06:09 jexp

Hey jexp, thanks for the reply. Apologies for the unclean code, I will be more careful with presenting it better next time. Would I suggest continuing to discuss this issue here before continuing at the pull request? I will also make it better as soon as I can.

So I was trying to run this command:

graphql load --csv reviews.txt --mutation corruptionIn --mapping '{ "url" : "commentary", "description" : "stars"}'

And I had defined this resolver in src/resolvers/Mutations.js from my most minimum example:

async function corruptionIn(parent, args, context, info) {
	const userId = getUserId(context)
	console.log("All arguments are: " + JSON.stringify(args)) 
  return context.db.mutation.createLinkC(
    {
      data: {
        url: args.url,
        description: args.description,
        postedBy: args.postedBy,
      },
    },
  )
}

Also running this mutation in the graphql playground, it worked:

mutation {
  corruptionIn(
    url: "sasasdasdd"
    description: "asddatabase into a GraphQL API"
    postedBy: "heey"
  ) {
    description
    id
  }
}

Would you think it still might be related to the mutation name in the grapqhl load command or in some other part of my command? I tried to replicate the example described in the README.md in your project page. Would you see any part where I implemented it incorrectly? The names of the mutations may be very strange as I was chucking the mutations from another project in, which may have seemed confusing.

daquintero avatar Sep 10 '18 17:09 daquintero