graphql-core icon indicating copy to clipboard operation
graphql-core copied to clipboard

Support extending interfaces

Open sebastiandev opened this issue 4 years ago • 4 comments

Reporting issues with GraphQL-core 3

The GraphQL protocol already supports interfaces extending other interfaces like

interface Identifiable {
  id: ID!
}

interface Resource implements Identifiable {
  id: ID!
  name: String!
}

type SomeResource implements Resource {
  id: ID!
  name: String!
}

When loading the schema we get an error

File "/usr/local/lib/python3.6/site-packages/graphql/type/validate.py", line 91, in assert_valid_schema
   raise TypeError("\n\n".join(error.message for error in errors))
   TypeError: Type SomeResource must implement Identifiable because it is implemented by Resource.

This can be solved by doing

type SomeResource implements Resource & Identifiable {
  id: ID!
  name: String
}

But its a bit annoying

sebastiandev avatar Nov 22 '21 14:11 sebastiandev

Hi @sebastiandev. Your example should actually work. Which version of GraphQL-core are you using and can you post the exact code that produces this error?

Cito avatar Nov 22 '21 16:11 Cito

Just noticed this was implemented in v3.1 only. Maybe you're still on v3.0?

Cito avatar Nov 22 '21 16:11 Cito

I'm on 3.1.6 using Ariadne. Looks like it supports an interface implementing another, but then it shows that error message

interface Node {
  id: String!
}

type PageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

interface Identifiable implements Node {
    id: String!
    legacy_id: Int
}

type AccountEdge {
  cursor: String!
  node: Account
}

type AccountConnection {
  pageInfo: PageInfo!
  edges: [AccountEdge]
}

type Account implements Identifiable {
  id: String!
  legacy_id: Int
  email: String
  customers: AccountConnection
}

sebastiandev avatar Nov 22 '21 19:11 sebastiandev

Hm, I still can't reproduce it with 3.1. Can you double-check the version with print(graphql.version_info) and post some Python code (not just SDL) that creates the error message above?

Cito avatar Nov 23 '21 16:11 Cito