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

Cannot work Nearby as concurrently using graphql-go #560

Closed
vishnutm opened this issue May 16, 2020 · 2 comments
Closed

Cannot work Nearby as concurrently using graphql-go #560

vishnutm opened this issue May 16, 2020 · 2 comments

Comments

@vishnutm
Copy link

@tidwall
Currently, try to perform Nearby function in driver detail in a concurrent manner. I currently use the graphql-go method to fetch the APIs.

current Nearby function

Screenshot from 2020-05-17 00-07-23

My go-routine method (Resolve function)

`func GetNearbyUser() *graphql.Field {
return &graphql.Field{
Type: graphql.NewList(types.NearbyType),
Args: graphql.FieldConfigArgument{

		"latitude": &graphql.ArgumentConfig{
			Type: graphql.NewNonNull(graphql.Float),
		},

		"longitude": &graphql.ArgumentConfig{
			Type: graphql.NewNonNull(graphql.Float),
		},

		"collection": &graphql.ArgumentConfig{
			Type: graphql.NewNonNull(graphql.String),
		},

		"radius": &graphql.ArgumentConfig{
			Type:         graphql.Float,
			DefaultValue: 2000.00,
		},
	},

	Resolve: func(params graphql.ResolveParams) (interface{}, error) {

		ch := make(chan []types.NearbyLocation)

		go func() {
			var Lat = params.Args["latitude"].(float64)
			var Long = params.Args["longitude"].(float64)
			var radius = params.Args["radius"].(float64)
			var collection = params.Args["collection"].(string)
			response, _ := tile38.Nearby(collection, Lat, Long, radius)
			ch <- response
		}()

		return func() interface{} {

			return <-ch
		}, nil

	},
}

}`

Error Result

query : query {nearbyUser(collection:"driver",latitude:8.55652,longitude:76.872894,radius:2000){latitude,longitude,id}}

Screenshot from 2020-05-16 23-14-40
Uploading Screenshot from 2020-05-16 23-14-30.png…

@tidwall
Copy link
Owner

tidwall commented May 17, 2020

The error you are getting does not appear to be related to Tile38 and I'm unfamiliar with graphql.

But at first glance, you appear to be running into some type of Go syntax error.

Perhaps your Resolve function should be something like:

Resolve: func(params graphql.ResolveParams) (interface{}, error) {
	return func() (interface{}, error) {
		var Lat = params.Args["latitude"].(float64)
		var Long = params.Args["longitude"].(float64)
		var radius = params.Args["radius"].(float64)
		var collection = params.Args["collection"].(string)
		resp, err := tile38.Nearby(collection, Lat, Long, radius)
		return resp, err
	}, nil
}

You may want to ask this question on a graphql-go forum.

@vishnutm
Copy link
Author

@tidwall, Thank you for your valuable suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants