nicolasdao / graphql-s2s

Add GraphQL Schema support for type inheritance, generic typing, metadata decoration. Transpile the enriched GraphQL string schema into the standard string schema understood by graphql.js and the Apollo server client.
Other
187 stars 15 forks source link

Space between @directive definition and parameter list breaks parsing #21

Closed eibhleag closed 6 years ago

eibhleag commented 6 years ago

Hi @nicolasdao & folks, really appreciate your work on this library - type inheritance is especially useful :-)

Came across the following issue when adding custom directives to our Schema.

Example Schema fragment:

directive @example(message: String) on FIELD_DEFINITION

Expected Behaviour:

Calling transpileSchema passes the input through unchanged.

Actual Behaviour:

node_modules/graphql-s2s/src/graphmetadata.js:38
                const dInstances = schema.match(new RegExp(`${directiveName}(.*?)░`, 'g')) || []

SyntaxError: Invalid regular expression: /@example(message:(.*?)░/: Unterminated group
    at new RegExp (<anonymous>)
    at d.forEach.directive (node_modules/graphql-s2s/src/graphmetadata.js:38:35)
    at Array.forEach (<anonymous>)
    at removeDirectives (node_modules/graphql-s2s/src/graphmetadata.js:32:4)
    at extractGraphMetadata (node_modules/graphql-s2s/src/graphmetadata.js:109:43)
    at removeGraphMetadata (node_modules/graphql-s2s/src/graphmetadata.js:158:15)
    at chain.next (node_modules/graphql-s2s/src/graphqls2s.js:778:15)
    at Object.next (node_modules/graphql-s2s/src/utilities.js:22:45)
    at Object.transpileSchema (node_modules/graphql-s2s/src/graphqls2s.js:778:4)
    at Object.<anonymous> (example.js)

Workaround:

Inserting a space between the @directive and its parameter list prevents the error:

directive @example (message: String) on FIELD_DEFINITION
glennvgastel commented 6 years ago

Hi @eibhleag and thank you for bringing this to our attention. I'll have a look and see if I can create a quick fix.

nicolasdao commented 6 years ago

Thanks a lot for warning us about that issue @eibhleag.

I've just fixed this. Install the latest version(0.17.1) and you should be fine.

Thanks for the kind words and your support.

Cheers,

Nic