Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Fields with arguments cause GraphQL Error #190

Closed
smkhalsa opened this issue Feb 8, 2019 · 4 comments
Closed

Fields with arguments cause GraphQL Error #190

smkhalsa opened this issue Feb 8, 2019 · 4 comments

Comments

@smkhalsa
Copy link
Contributor

smkhalsa commented Feb 8, 2019

After upgrading from 2.1.1 to 2.3.1, I get the following error immediately upon starting my server:


/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:1463
  throw (0, _error.syntaxError)(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat((0, _lexer.getTokenDesc)(token)));
  ^
GraphQLError: Syntax Error: Expected :, found (
    at syntaxError (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/error/syntaxError.js:24:10)
    at expect (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:1463:32)
    at parseInputValueDef (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:921:3)
    at many (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:1523:16)
    at parseInputFieldsDefinition (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:1083:50)
    at parseInputObjectTypeDefinition (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:1067:16)
    at parseTypeSystemDefinition (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:736:16)
    at parseDefinition (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:142:16)
    at many (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:1520:16)
    at parseDocument (/Users/smkhalsa/code/kundalini-server/node_modules/neo4j-graphql-js/node_modules/graphql/language/parser.js:113:18)
error Command failed with exit code 1.
@johnymontana
Copy link
Contributor

That looks like a GraphQL syntax error - parsing the type definition SDL I'm assuming. Can you share the typedefs you're using and how you are calling augmentSchema or makeAugmentedSchema?

@smkhalsa
Copy link
Contributor Author

It looks like the issue is with fields that have arguments. For example, with this schema:

enum ImageSize {
  XSmall
  Small
  Medium
  Large
  XLarge
}

type Image {
  id: ID!
  url(size: ImageSize): String
}

In this example, I want to use a custom resolver to generate the URL.

@smkhalsa smkhalsa changed the title Regression: 2.3.1 causes GraphQL Error Fields with arguments cause GraphQL Error Feb 10, 2019
@johnymontana
Copy link
Contributor

If you are implementing a custom resolver for Image.url then you should add the @neo4j_ignore directive to the field, indicating it should be excluded from the schema augmentation and Cypher query generation process (I'm sorry, this isn't very well documented yet).

So your example should look something like this:

const typeDefs = `
enum ImageSize {
  XSmall
  Small
  Medium
  Large
  XLarge
}

type Image {
  id: ID!
  url(size: ImageSize): String @neo4j_ignore
}
`

const resolvers = {
  Image: {
    url: (object, params, context, resolveInfo) => {
      return `http://foo.bar/${params.size}`;
    }
  }
};

const schema = makeAugmentedSchema({ typeDefs, resolvers });

...

Then this GraphQL query:

{
  Image(first: 1) {
    id
    url(size: XLarge)
  }
}

would return

{
  "data": {
    "Image": [
      {
        "id": "foo",
        "url": "http://foo.bar/XLarge"
      }
    ]
  }
}

The generated Cypher query then excludes the url property, allowing the custom resolver to be called:

MATCH (`image`:`Image` ) RETURN `image` { .id } AS `image` SKIP $offset LIMIT $first
{ offset: 0, first: 1 }

We initially had some logic to automatically add the @neo4j_ignore directive to fields where a custom resolver was provided, however it went a little rogue in some edge cases as you can see in #189 so we temporarily removed that functionality until we can think of a better way to handle it.

Could you give the @neo4j_ignore directive a try and let us know if it works for you?

@smkhalsa
Copy link
Contributor Author

@johnymontana That works! Thank you

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants