Comments (4)
You can use the ContructSubscription
function to print and debug the output graphql string
The issue is on the datapointsList
variable. You need to define the type of that input variable so the library can reflect it to the equivalent GraphQL input type.
type Foo map[string]interface{}
datapointsList := Foo{ ... }
from go-graphql-client.
For reference, this is the code that I use for the subscription:
type DataPointsSubscription struct {
Subscription struct {
DataPointsSubscription []struct {
Value graphql.String `graphql:"value"`
} `graphql:"DataPointsSubscription(datapointList: $datapointList)"`
} `graphql:"subscription"`
}
func SubscribeDataPointValue(authToken string, datapoints []appdb.Datapoint) error {
client := graphql.NewSubscriptionClient("...").
WithConnectionParams(map[string]interface{}{
"headers": map[string]string{
"Authorization": "bearer " + authToken,
},
}).
WithProtocol(graphql.GraphQLWS).
OnError(func(sc *graphql.SubscriptionClient, err error) error {
return fmt.Errorf("subscription client error: %v", err)
})
defer client.Close()
datapointsList := []map[string]string{}
for _, dp := range datapoints {
datapointsList = append(datapointsList, map[string]string{
"serialNumber": dp.DeviceID,
"channelNumber": dp.ChannelID,
"datapointId": dp.Datapoint,
})
}
var sub DataPointsSubscription
variables := map[string]interface{}{
"datapointList": datapointsList,
}
str, err := client.Subscribe(&sub, variables, func(message []byte, err error) error {
if err != nil {
fmt.Println("Subscription error:", err)
return err
}
for _, dp := range sub.Subscription.DataPointsSubscription {
fmt.Println("Received data point value:", dp.Value)
fmt.Printf("%+v\n", dp)
}
return nil
}, nil)
if err != nil {
return fmt.Errorf("establishing subscription: %v", err)
}
fmt.Println(str)
if err := client.Run(); err != nil {
return fmt.Errorf("running client: %v", err)
}
return nil
}
from go-graphql-client.
Thank you very much for your quick response! This resolved my problem and now I know how to see the output. Maybe that would be nice to have in the readme? Shall I create a PR?
from go-graphql-client.
There is a docs section for this, but it isn't detailed. Feel free to improve the README docs.
from go-graphql-client.
Related Issues (20)
- How can we handle multi-part request to add "file" in the request? HOT 3
- UUID Error HOT 2
- like uuid used using type uuid string to send to hasura what to do for bigint HOT 1
- jsonb type declaration HOT 17
- GraphQL subscription sequence is not guaranteed HOT 3
- field 'update_schema_event' not found in type: 'query_root', HOT 3
- representing nested query and foreign key HOT 1
- Upgrade dependencies HOT 2
- Invalid serialisation containing commas with embedded struct HOT 1
- Date/times as variable paramaters to hasura HOT 1
- Can't get graphql-ws protocol working HOT 4
- Add Unwrap support to Errors type to support errors.Is and errrors.As.
- How to refresh accessToken in onError HOT 2
- Get list/map of subscriptions HOT 2
- Retrieve response body and status code HOT 1
- Error type should have Path field HOT 1
- mutation query doesn't allow optional params HOT 2
- ExecRaw does not respect OperationName option HOT 1
- ExecRaw vs Mutate/MutateRaw HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-graphql-client.