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

gql: field argument for input objects #1531

Closed
benneq opened this issue Aug 15, 2018 · 2 comments
Closed

gql: field argument for input objects #1531

benneq opened this issue Aug 15, 2018 · 2 comments

Comments

@benneq
Copy link

benneq commented Aug 15, 2018

I'm not sure whether this is a feature request, a bug report or a documentation issue.

I'm using apollo-server-express 2.0.2 with this code:

const { ApolloServer, gql } = require('apollo-server-express');

const typeDefs = gql`
    ...
`

const resolvers = {
    Query: { ... }
}

const app = express();
const server = new ApolloServer({ typeDefs, resolvers });
server.applyMiddleware({ app });

Now I was trying to use Field Arguments with an input object:

const typeDefs = gql`
    input GeoFilter {
        location: [Float]
        distance(unit: String): Float
    }
`

This results in an error:

GraphQLError: Syntax Error: Expected :, found (

When switching from input to type everything works:

const typeDefs = gql`
    type GeoFilter {
        location: [Float]
        distance(unit: String): Float
    }
`

I haven't found anything on the internet about using input with field arguments.

How does this work? Or what am I missing?

@sbrichardson
Copy link
Contributor

sbrichardson commented Aug 15, 2018

Does this maybe help?

Dumbly assumes to return a GeoFilter, would probably return a list of locations etc. You wouldn't really pass an argument to the input, you would just pass another property, since input is basically an argument. It can be (input, another) or just add inside the input type

const typeDefs = gql`

  type GeoFilter {
    location: [Float]
    distance(unit: String): Float
  }

  input GeoFilterInput {
    location: [Float]
    distance: Float
  }

  extend type Query {
    createLocation(input: GeoFilterInput!): GeoFilter
    findLocation(input: GeoFilterInput!): GeoFilter
  }


query {
  findLocation(input: { location: [123, 123], distance: 25 }) {
    location
    distance(unit: 'km')
  }
}

// results

@benneq
Copy link
Author

benneq commented Aug 16, 2018

Thank you. I think it was a little too late in the night for me... I mixed up a few things.

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

2 participants