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

Assertion error with a query including inline fragments #1880

Closed
raviqqe opened this issue Jun 12, 2017 · 4 comments
Closed

Assertion error with a query including inline fragments #1880

raviqqe opened this issue Jun 12, 2017 · 4 comments

Comments

@raviqqe
Copy link

raviqqe commented Jun 12, 2017

Given ./foo.js:

import { graphql } from 'relay'

export const query = graphql`
  query fooQuery {
    foo {
      ... on Bar {
        bar
      }
      ... on Baz {
        baz
      }
    }
  }
`

and ./schema.graphql:

type Bar {
        bar: String!
}

type Baz {
        baz: String!
}

union Foo = Bar | Baz

type Query {
        foo: Foo!
}

Then, run the following command.

relay-compiler --src . --schema schema.graphql

And, I got errors.

HINT: pass --watch to keep watching for changes.
Parsed default in 0.03s

Writing default
Error: Expected undefined to be a GraphQL leaf type.
    at invariant (/Users/me/.config/yarn/global/node_modules/graphql/jsutils/invariant.js:19:11)
    at assertLeafType (/Users/me/.config/yarn/global/node_modules/graphql/type/definition.js:93:27)
    at generateIDSelections (/Users/me/.config/yarn/global/node_modules/relay-compiler/bin/relay-compiler:6588:20)
    at transformField (/Users/me/.config/yarn/global/node_modules/relay-compiler/bin/relay-compiler:6531:23)
    at /Users/me/.config/yarn/global/node_modules/relay-compiler/bin/relay-compiler:6514:15
    at Array.map (native)
    at transformNode (/Users/me/.config/yarn/global/node_modules/relay-compiler/bin/relay-compiler:6512:37)
    at /Users/me/.config/yarn/global/node_modules/relay-compiler/bin/relay-compiler:6506:28
    at Array.reduce (native)
    at transform (/Users/me/.config/yarn/global/node_modules/relay-compiler/bin/relay-compiler:6505:21)

Is this a bug of the compiler or am I missing something?

@raviqqe
Copy link
Author

raviqqe commented Jun 12, 2017

I found a hacking solution for this of adding some type which contains a field of an ID type like the below.

type Hack {
        id: ID
}

...

The problem is that bin/relay-compiler calls context.schema.getType(ID_TYPE) internally.
However, GraphQLSchema class seems to omit unused types from its type map.
The author of relay-compiler may have assumed that every built-in type is available by GraphQLSchema.getType().

@wincent
Copy link
Contributor

wincent commented Sep 11, 2017

Thanks for the input here. We're currently going through old issues that appear to have gone stale (ie. not updated in about the last 3 months) because the volume of material in the issue tracker is becoming hard to manage. If this is still important to you please comment and we'll re-open this.

Thanks once again!

@wincent wincent closed this as completed Sep 11, 2017
@Forfold
Copy link

Forfold commented Oct 18, 2017

I am seeing this problem with the relay-compiler, although the query works in GraphiQL. We have a Union inside of a fragment that gives this same error (Expected undefined to be a GraphQL leaf type) however with no stack trace. Can this issue be reopened? @wincent

(This was tested with relay and compiler on v1.4.1)

export default createRefetchContainer(
  ScheduleDetails,
  graphql`
    fragment ScheduleDetailsAssignments on ScheduleAssignment {
      id
      target {
        ... on Rotation {
          id
          name
        }
      }
    }
   
  `,
  graphql`
    query ScheduleDetailsQuery($id: String!) {
      schedule(id: $id) {
        assignments {
          ...ScheduleDetailsAssignments
        }
      }
    }
  `
)

@jakubgs
Copy link

jakubgs commented Jan 15, 2018

I'm experiencing the same issue:

Writing default
ERROR:
Expected undefined to be a GraphQL leaf type.
From: CodegenRunner.write
    at invariant (./node_modules/graphql/jsutils/invariant.js:18:11)
    at assertLeafType (./node_modules/graphql/type/definition.js:102:47)
    at generateIDSelections (./node_modules/relay-compiler/bin/relay-compiler:7806:20)
    at transformField (./node_modules/relay-compiler/bin/relay-compiler:7762:23)
    at ./node_modules/relay-compiler/bin/relay-compiler:7747:15
    at Array.map (native)
    at transformNode (./node_modules/relay-compiler/bin/relay-compiler:7745:37)
    at transformField (./node_modules/relay-compiler/bin/relay-compiler:7760:26)
    at ./node_modules/relay-compiler/bin/relay-compiler:7747:15
    at Array.map (native)

I have no idea what this means. I'm just trying to query a union inside of an object:

some_attr {
  attribute {
    ... on SomeObject {
      something
    }
    ... on AnotherObject {
      anotherthing
    }
  }
}

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

No branches or pull requests

4 participants