# Custom Query not working with Float and Integer types

**URL:** <https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998>\
**Category:** GraphQL\
**Tags:** kind:bug, custom-directive\
**Created:** [February 28, 2021, 2:06am UTC](https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998 "2021-02-28T02:06:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geoff.Nunan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/geoff.nunan/32/9508_2.png) [@Geoff.Nunan](https://discuss.dgraph.io/u/Geoff.Nunan)\
**Post date:** [February 28, 2021, 2:06am UTC](https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998/1 "2021-02-28T02:06:00Z")

</div>

I am using dgraph version 20.11.02

I have a simple rest API which returns the following json

```auto
{"id":"0x1a","class":"Time","label":"Label","value":10,"standardValue":1.1,"text":"Test Single Reason"}

```

In my schema, I have the following:

```auto
type ReasonTest @remote {
    id : ID!
    class : String!
    label : String!
    text : String!
    value : Int
    standardValue : Float
}

type Query{
    getTest: ReasonTest @custom(http:{
        url: "http://host.docker.internal:10000/getTest",
        method: GET
    })
}

```

when I query getTest, I get the string types OK, but float and integer types are null

{  
“data”: {  
“getTest”: {  
“id”: “0x1a”,  
“label”: “Label”,  
“text”: “Test Single Reason”,  
“class”: “Time”,  
“value”: null,  
“standardValue”: null  
}  
},  
“extensions”: {  
“tracing”: {  
“version”: 1,  
“startTime”: “2021-02-28T01:56:18.5597489Z”,  
“endTime”: “2021-02-28T01:56:18.5803396Z”,  
“duration”: 20618800  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![JatinDevDG](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jatindevdg/32/3417_2.png) [@JatinDevDG](https://discuss.dgraph.io/u/JatinDevDG)\
**Post date:** [March 3, 2021, 9:20am UTC](https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998/3 "2021-03-03T09:20:21Z")

</div>

Hi @Geoff.Nunan, Welcome to Dgraph community!!  
Ideally it shouldn’t happen. Can you please provide some more details like how you are constructing and returning response from rest API.  
I am able to get even the Int and float in response with our implementation of rest API.

---

<div class="post-metadata">

**Author:** ![Geoff.Nunan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/geoff.nunan/32/9508_2.png) [@Geoff.Nunan](https://discuss.dgraph.io/u/Geoff.Nunan)\
**Post date:** [March 5, 2021, 2:52am UTC](https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998/4 "2021-03-05T02:52:21Z")

</div>

Hi @JatinDevDG ,

I have implemented a very simple service in Golang that populates the following response variable

```auto
	var response []struct{
		Id graphql.ID `json:"id"`
		Class graphql.String `json:"class"`
		Label graphql.String `json:"label"`
		Text graphql.String `json:"text"`
		StandardValue graphql.Float `json:"standardValue"`
		EquipmentClass struct {
			Id graphql.ID `json:"id"`
			Name graphql.String `json:"name"`
		} `json:"equipmentClass"`
			EquipmentOverrides [] struct {
			Id graphql.ID `json:"id"`
			StandardValue graphql.Float `json:"standardValue"`
			Ignore graphql.Boolean `json:"ignore"`
		}`json:"equipmentOverrides"`
	}

```

Which then gets returned in the rest handler method using

```auto
json.NewEncoder(w).Encode(response)

```

---

<div class="post-metadata">

**Author:** ![Geoff.Nunan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/geoff.nunan/32/9508_2.png) [@Geoff.Nunan](https://discuss.dgraph.io/u/Geoff.Nunan)\
**Post date:** [March 5, 2021, 3:58am UTC](https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998/5 "2021-03-05T03:58:28Z")

</div>

I have tried to build a very simple schema and service, and the simple one works fine.

As my schema gets more complex, some fields return null.

Interestingly, when this occurs, if I rename the field in the schema and in the service it starts working again. I am literally just renaming the field that is returning null with no other changes.

---

<div class="post-metadata">

**Author:** ![Geoff.Nunan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/geoff.nunan/32/9508_2.png) [@Geoff.Nunan](https://discuss.dgraph.io/u/Geoff.Nunan)\
**Post date:** [March 7, 2021, 11:28am UTC](https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998/6 "2021-03-07T11:28:07Z")

</div>

@JatinDevDG I have isolated the bug.

It seems that having multiple types implementing an interface breaks @custom queries.

Steps to reproduce:  
1- Run the dgraph standalone docker container.  
2 - publich the following schema into it

```auto
type Item implements Base{
    name:String
    value:Float
}
type Order implements Base{
    name:String
    value:Float
}
interface Base {
    id:ID!
}
type Query{
    getCustomTest:[Item] @custom(http:{
        url: "http://host.docker.internal:8080/getTest",
        method: GET
    })
}

```

3- Write a simple golang service at the /getTest endpoint like this.

```auto
func getTest(w http.ResponseWriter, r *http.Request) {

	response := []domain.Item {{
		Id:"0x1",
		Name:"01",
		Value: 1,
	},{

		Id:"0x2",
		Name:"02",
		Value: 2,
	}}
	log.Print(response)
	json.NewEncoder(w).Encode(response)
}

```

4 - using GraphQL playground, query

```auto
query{
  getCustomTest{
    id
    name
    value
  }
}

```

I am getting the following response

```auto
{
  "data": {
    "getCustomTest": [
      {
        "id": "0x1",
        "name": null,
        "value": null
      },
      {
        "id": "0x2",
        "name": null,
        "value": null
      }
    ]
  },
  "extensions": {}
}

```

5 - Edit the schema to remove the interface like this:

```auto
type Item {
    id:ID!
    name:String
    value:Float
}
type Order {
    id:ID!
    name:String
    value:Float
}
type Query{
    getCustomTest:[Item] @custom(http:{
        url: "http://host.docker.internal:8080/getTest",
        method: GET
    })
}

```

Run the query again and you get the proper response

```auto
{
  "data": {
    "getCustomTest": [
      {
        "id": "0x1",
        "name": "01",
        "value": 1
      },
      {
        "id": "0x2",
        "name": "02",
        "value": 2
      }
    ]
  },
  "extensions": {}
}

```

---

<div class="post-metadata">

**Author:** ![JatinDevDG](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jatindevdg/32/3417_2.png) [@JatinDevDG](https://discuss.dgraph.io/u/JatinDevDG)\
**Post date:** [March 8, 2021, 7:31am UTC](https://discuss.dgraph.io/t/custom-query-not-working-with-float-and-integer-types/12998/7 "2021-03-08T07:31:59Z")

</div>

Hi @Geoff.Nunan , Thanks for detailed description of the bug. This bug is already fixed but not available in 20.11.02. We had similar kind of bug previously also [Custom field resolvers are not always called](http://discuss.hypermode.com/t/custom-field-resolvers-are-not-always-called/12489)

We made many changes related to JSON encoding in master branch which fix such type of bugs.  
These changes will be part of 21.03 release and currently available only in master branch only.  
PR:[perf(GraphQL): Generate GraphQL query response by optimized JSON encoding (GraphQL-730) by abhimanyusinghgaur · Pull Request #7371 · dgraph-io/dgraph · GitHub](https://github.com/dgraph-io/dgraph/pull/7371)
