Graphql: DateTime type behaviour problem

Created on 6 Oct 2017  路  2Comments  路  Source: graphql-go/graphql

a query with DateTime argument variable, it will be time.Time in go

query SiteDetail($from: DateTime!) {
  data(from: $from){
          from
  }
}

a query with DateTime argument in string, it will be string in go

query {
  data(from: "2017-10-06T03:40:00.000Z"){
          from
  }
}
from := params.Args["from"]
switch from.(type) {
    case string:
        fmt.Println("String")
    case time.Time:
        fmt.Println("Time")
}

if a query with DateTime argument variables in string, it should be converted to time.Time

bug

Most helpful comment

I'm pretty confident this was unintentional and just a bug. I've put in a PR to fix it (see above).

All 2 comments

I've just come across this exact issue. To clarify, the value from params.Args is a time.Time when the argument is given through a variable. It is a string when given directly. Consequently, the resolver needs to handle both cases. I'm unsure if this is intended or a bug, but it is definitely not expected behaviour as a developer interfacing with this package.

I'm pretty confident this was unintentional and just a bug. I've put in a PR to fix it (see above).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbuck picture bbuck  路  4Comments

rustysys-dev picture rustysys-dev  路  6Comments

conord33 picture conord33  路  6Comments

davejohnston picture davejohnston  路  3Comments

tobyjsullivan picture tobyjsullivan  路  5Comments