Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for custom scalar client-side usage #224

Merged
merged 4 commits into from
Dec 13, 2016
Merged

Conversation

Urigo
Copy link
Collaborator

@Urigo Urigo commented Dec 8, 2016

@glasser

Fixes #225

@DxCx
Copy link
Contributor

DxCx commented Dec 11, 2016

is there someone trying to fix this?
or i'll give it a go?

@glasser
Copy link
Contributor

glasser commented Dec 11, 2016 via email

@DxCx
Copy link
Contributor

DxCx commented Dec 12, 2016

Ok,
so i did look into it, and found the bug.
basiclly, to create a scheme, first we will use graphql to generate typedef to scheme.
when doing so, a GraphQLScalarType is being created, with default parse functions.

later on, we will run the function to bind resolvers.
However, this specific line: https://github.com/apollostack/graphql-tools/blob/master/src/schemaGenerator.ts#L280
replaces the placeholder scalar type with the one provided.
and then overrides the original type with the fields from the given scalar.
https://github.com/apollostack/graphql-tools/blob/master/src/schemaGenerator.ts#L293

however, all the arguments of the fields (which has arguments ofcourse) did not replace type.
so when comparing between the two (argType === scalarType) we will get a missmatch.

so, to sum this up, we have couple of choices:

  1. run a "fix" function on the scheme to fix arguments after resolvers placed.
  • IMO, this approach will hit performance of scheme compiling.
  1. remove this chunk of code which replaces the type on map:
    if (type instanceof GraphQLScalarType) {
      const resolveFn = resolveFunctions[typeName];
      if (resolveFn instanceof GraphQLScalarType) {
        const thisScalarType: GraphQLScalarType = resolveFn;
        schema.getTypeMap()[typeName] = thisScalarType;
      }
    }
  • however, this means that the original scalar given is not really used, only a copy of the handling functions. (easier fix)

@Urigo / @glasser / @helfer what do you think?

@stubailo
Copy link
Contributor

@DxCx I'd say we should just replace the functions and not the actual scalar instance.

@stubailo
Copy link
Contributor

(Like your approach 2)

@glasser
Copy link
Contributor

glasser commented Dec 12, 2016

So literally just delete the quoted block? That does appear to make the whole test suite pass (well, Uri's test actually has to be adjusted slightly to expect(result.errors).to.not.be.ok; instead of expect(result.errors.length

@DxCx DxCx changed the title test(custom-scalar): Add custom scalar client-side usage failing test fix for custom scalar client-side usage Dec 12, 2016
@DxCx
Copy link
Contributor

DxCx commented Dec 12, 2016

ok @Urigo,
i just pushed the fix on your branch and updated the PR.
@helfer / @stubailo please approve and merge :)

@DxCx DxCx added the ready label Dec 12, 2016
@helfer helfer merged commit eb8ee9c into master Dec 13, 2016
@helfer helfer deleted the custom-scalar-failing-test branch December 13, 2016 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants