Skip to content

Extending input types #641

Closed
Closed
@tamlyn

Description

@tamlyn

I'm finding that extend doesn't work as expected for input types.

// server.js
const express = require('express')
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express')
const { makeExecutableSchema } = require('graphql-tools')
const bodyParser = require('body-parser')

const app = express()
const typeDefs = `
type Query {
  getFoo: Foo
}
type Foo {
  foo: String
}
extend type Foo {
  bar: String
}

type Mutation {
  updateFoo(input: FooInput): Foo
}
input FooInput {
  foo: String
}
extend input FooInput {
  bar: String
}
`

const resolvers = {
  Query: {
    getFoo: () => ({ foo: 'hey', bar: 'ho' }),
  },
  Mutation: {
    updateFoo: (_, { input }) => input,
  },
}

const schema = makeExecutableSchema({ typeDefs, resolvers })

app.use(bodyParser.json({ limit: '50mb' }))
app.use('/graphql', graphqlExpress({ schema }))
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))

app.listen(8080)
# start the server
$ node server.js

# try a query
$ curl -XPOST -d'{"query":"{getFoo{foo, bar}}"}' -H 'Content-type: application/json' http://localhost:8080/graphql
{"data":{"getFoo":{"foo":"hey","bar":"ho"}}}

# try a mutation
$ curl -XPOST -d '{"query":"mutation($input: FooInput){updateFoo(input: $input){foo, bar}}","variables":{"input":{"foo":"ey","bar":"oh"}}}' -H 'Content-type: application/json' http://localhost:8080/graphql
{"errors":[{"message":"Variable \"$input\" got invalid value {\"foo\":\"ey\",\"bar\":\"oh\"}; Field \"bar\" is not defined by type FooInput.","locations":[{"line":1,"column":10}]}]}

Is this a bug, a deliberate omission or just a feature that has not yet been implemented?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions