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

Unable to query using an interface type #500

Open
Rosencrantz opened this issue Aug 27, 2020 · 3 comments
Open

Unable to query using an interface type #500

Rosencrantz opened this issue Aug 27, 2020 · 3 comments

Comments

@Rosencrantz
Copy link

Rosencrantz commented Aug 27, 2020

I have a very basis typedef:

interface Node {
    id: ID!
    name: String
}

type Entity implements Node {
    id: ID!
    name: String!
    jurisdiction: String
}

When i use makeAugmentedSchema it produces the following which i can see in the schema tab of the graphql playground:

directive @cypher(statement: String) on FIELD_DEFINITION
directive @relation(
  name: String
  direction: _RelationDirections
  from: String
  to: String
) on FIELD_DEFINITION | OBJECT
directive @additionalLabels(labels: [String]) on OBJECT
directive @MutationMeta(
  relationship: String
  from: String
  to: String
) on FIELD_DEFINITION
directive @neo4j_ignore on FIELD_DEFINITION
directive @specifiedBy(url: String!) on SCALAR
input _EntityFilter {
  AND: [_EntityFilter!]
  OR: [_EntityFilter!]
  id: ID
  id_not: ID
  id_in: [ID!]
  id_not_in: [ID!]
  id_contains: ID
  id_not_contains: ID
  id_starts_with: ID
  id_not_starts_with: ID
  id_ends_with: ID
  id_not_ends_with: ID
  name: String
  name_not: String
  name_in: [String!]
  name_not_in: [String!]
  name_contains: String
  name_not_contains: String
  name_starts_with: String
  name_not_starts_with: String
  name_ends_with: String
  name_not_ends_with: String
  jurisdiction: String
  jurisdiction_not: String
  jurisdiction_in: [String!]
  jurisdiction_not_in: [String!]
  jurisdiction_contains: String
  jurisdiction_not_contains: String
  jurisdiction_starts_with: String
  jurisdiction_not_starts_with: String
  jurisdiction_ends_with: String
  jurisdiction_not_ends_with: String
}
input _EntityInput {
  id: ID!
}
enum _EntityOrdering {
  id_asc
  id_desc
  name_asc
  name_desc
  jurisdiction_asc
  jurisdiction_desc
  _id_asc
  _id_desc
}
type _Neo4jDate {
  year: Int
  month: Int
  day: Int
  formatted: String
}
input _Neo4jDateInput {
  year: Int
  month: Int
  day: Int
  formatted: String
}
type _Neo4jDateTime {
  year: Int
  month: Int
  day: Int
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  timezone: String
  formatted: String
}
input _Neo4jDateTimeInput {
  year: Int
  month: Int
  day: Int
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  timezone: String
  formatted: String
}
type _Neo4jLocalDateTime {
  year: Int
  month: Int
  day: Int
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  formatted: String
}
input _Neo4jLocalDateTimeInput {
  year: Int
  month: Int
  day: Int
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  formatted: String
}
type _Neo4jLocalTime {
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  formatted: String
}
input _Neo4jLocalTimeInput {
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  formatted: String
}
type _Neo4jPoint {
  x: Float
  y: Float
  z: Float
  longitude: Float
  latitude: Float
  height: Float
  crs: String
  srid: Int
}
input _Neo4jPointDistanceFilter {
  point: _Neo4jPointInput!
  distance: Float!
}
input _Neo4jPointInput {
  x: Float
  y: Float
  z: Float
  longitude: Float
  latitude: Float
  height: Float
  crs: String
  srid: Int
}
type _Neo4jTime {
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  timezone: String
  formatted: String
}
input _Neo4jTimeInput {
  hour: Int
  minute: Int
  second: Int
  millisecond: Int
  microsecond: Int
  nanosecond: Int
  timezone: String
  formatted: String
}
input _NodeFilter {
  AND: [_NodeFilter!]
  OR: [_NodeFilter!]
  id: ID
  id_not: ID
  id_in: [ID!]
  id_not_in: [ID!]
  id_contains: ID
  id_not_contains: ID
  id_starts_with: ID
  id_not_starts_with: ID
  id_ends_with: ID
  id_not_ends_with: ID
  name: String
  name_not: String
  name_in: [String!]
  name_not_in: [String!]
  name_contains: String
  name_not_contains: String
  name_starts_with: String
  name_not_starts_with: String
  name_ends_with: String
  name_not_ends_with: String
}
input _NodeInput {
  id: ID!
}
enum _NodeOrdering {
  id_asc
  id_desc
  name_asc
  name_desc
}
enum _RelationDirections {
  IN
  OUT
}
type Entity implements Node {
  id: ID!
  name: String!
  jurisdiction: String
  _id: String
}
type Mutation {
  CreateEntity(id: ID, name: String!, jurisdiction: String): Entity
  UpdateEntity(id: ID!, name: String, jurisdiction: String): Entity
  DeleteEntity(id: ID!): Entity
  MergeEntity(id: ID!, name: String, jurisdiction: String): Entity
}
interface Node {
  id: ID!
  name: String
}
type Query {
  Node(
    id: ID
    name: String
    _id: String
    first: Int
    offset: Int
    orderBy: [_NodeOrdering]
    filter: _NodeFilter
  ): [Node]
  Entity(
    id: ID
    name: String
    jurisdiction: String
    _id: String
    first: Int
    offset: Int
    orderBy: [_EntityOrdering]
    filter: _EntityFilter
  ): [Entity]
}

When I use the playground to create a new Entity it produces a Node with two labels (Node and Entity). If I then try to query for all items with a node type using the following:

query {
  Node {
    id
  }
}

I am presented with the following error:

message": "Abstract type Node must resolve to an Object type at runtime for field Query.Node with value { FRAGMENT_TYPE: null, id: \"foobar\" }, received \"null\". Either the Node type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.

The object that is returned to the automatically generated __resolveType function has null as the FRAGMENT_TYPE. If I run my application with the debug settings on I can see that the generated Cypher does not contain a list of node types in Node_DerivedTypes.

I'm using:

neo4j-graphql-js 2.15.1
neo4j-driver 4.1.0
apollo-server 2.16.1

@Rosencrantz
Copy link
Author

For anyone that comes along suffering from the same problem as the one described above. I managed to resolve this for myself by adjust my schema and renaming my "id" fields to something else.

My revised typedefs file looked like this:

interface Node {
    nodeId: ID! #Used to be id
    name: String
}

type Entity implements Node {
    nodeId: ID!
    name: String!
    jurisdiction: String
}

Once I'd made this adjustment I was then able to query using the Node interface.

@hungry-thom
Copy link

I have come across this problem as well. I tried renaming my id fields to no avail. I used the example at https://grandstack.io/docs/graphql-interface-union-types/ exactly as presented and continue to run into the same problem. Any ideas?

@michaeldgraham
Copy link
Collaborator

#608

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

No branches or pull requests

3 participants