0

I am using express-graphql and I am trying to implement interfaces, like here and here. However, I do not know how to implement those, since the notation people use is totally different from what I am used to in nodejs.

In the second answer, for example, somebody wrote this:

type Query {
  blocks: [ ContentBlock! ]!
}

type Video implements ContentBlock {
  id: ID!
  url: String!
}

type Quote implements ContentBlock {
  id: ID!
  body: String!
  author: String
}

type Advertisement implements ContentBlock {
  id: ID!
  src: String!
  backgroundColor: String
}


interface ContentBlock {
  id: ID!
}

My own definitions in express-graphql look more like this however:

const Quote = new GraphQLObjectType({
  name: "Quote",
  fields: () => ({
    id: { type: GraphQLID },
    body: { type: GraphQLString },
    author: { type: GraphQLString },
  }),
});

Could somebody help me out here? I am also wondering where to find this information in general. I looked at the documentation of express-graphql on github but I couldn't find anything explaining how to do interfaces or unions.

  • 1
    schema-first ve code-first ... https://stackoverflow.com/a/45396417/6124657 – xadm May 19 '21 at 21:21
  • You're using https://graphql.org/graphql-js/type. You can just create a `GraphQLInterfaceType` or `GraphQLUnionType`. – Bergi May 20 '21 at 00:36

0 Answers0