Code Monkey home page Code Monkey logo

Comments (6)

ClarenceMG avatar ClarenceMG commented on August 24, 2024 1

I haven't tested yet.
I will test as soon as possible and I will let you know.
Thank you.

from sahb.graphqlclient.

chelliwell avatar chelliwell commented on August 24, 2024

I'm on the sofa now lol, so can't examine in detail - but my immediate thought was that it might be a case issue. See #69
I find Wireshark a good tool for this kind of 'hidden' issue - look for the subscription request, the Ack, the sub messages being sent out. Often helps identify where the chain is broken.
FWIW....

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 24, 2024

I have created a example for you:

using System;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SAHB.GraphQLClient;
using SAHB.GraphQLClient.FieldBuilder;
using SAHB.GraphQLClient.FieldBuilder.Attributes;
using SAHB.GraphQLClient.QueryGenerator;
using SAHB.GraphQLClient.Subscription;

namespace LiftStatus
{
    class Program
    {
        
        static async Task Main(string[] args)
        {
            using (var wssClient = GraphQLSubscriptionWebSocketClient.Default())
            {
                // Connect
                var graphQLSubscriptionClient = await wssClient.Connect(new Uri("ws://snowtooth.moonhighway.com/graphql"));
                if (!graphQLSubscriptionClient.IsConnected)
                {
                    Console.WriteLine("Could not connect!");
                    Console.ReadKey();

                    return;
                }

                // Initilize
                await graphQLSubscriptionClient.Initilize();
                if (!graphQLSubscriptionClient.IsInitilized)
                {
                    Console.WriteLine("Could not initilize!");
                    Console.ReadKey();

                    return;
                }

                var operation = await graphQLSubscriptionClient.ExecuteOperation<Data>();
                operation.DataRecieved += (sender, e) =>
                {
                    Console.WriteLine("Lift changed: " + e.ReceivedData.Data.LiftStatusChange.Name);
                };

                IGraphQLHttpClient client = GraphQLHttpClient.Default();

                while (true)
                {
                    await SetLiftStatus(client, "astra-express", LiftStatus.OPEN);

                    Console.ReadKey();
                }
            }
        }

        static async Task<Lift> SetLiftStatus(IGraphQLHttpClient client, string id, LiftStatus liftStatus)
        {
            var output = await client.Execute<SetLiftStatus>(GraphQLOperationType.Mutation, url: "http://snowtooth.moonhighway.com/graphql", arguments:
                new GraphQLQueryArgument[] { new GraphQLQueryArgument<SetLiftStatus>("id", id, e => e.Lift),
                new GraphQLQueryArgument<SetLiftStatus>("status", liftStatus, e => e.Lift)});
            return output.Lift;
        }
    }

    public class Lift
    {
        public string Name { get; set; }
    }

    [JsonConverter(typeof(StringEnumConverter))]
    public enum LiftStatus
    {
        [EnumMember(Value = "OPEN")]
        OPEN,
        [EnumMember(Value = "CLOSED")]
        CLOSED,
        [EnumMember(Value = "HOLD")]
        HOLD
    }

    public class SetLiftStatus
    {
        [GraphQLArguments("id", "ID!", "id", true)]
        [GraphQLArguments("status", "LiftStatus!", "status", true, true)]
        [GraphQLFieldName("setLiftStatus")]
        public Lift Lift { get; set; }
    }

    public class LiftStatusChange
    {
        public string Name { get; set; }
        public int Capacity { get; set; }
    }

    public class Data
    {
        public LiftStatusChange LiftStatusChange { get; set; }
    }
}

This produces the following output:
image

Note I'm using the latest version from develop - a preview NuGet feed is available (please see the readme) :)

Edit: If you remove e => e.Lift in the SetLiftStatus it should work with the version on NuGet.

from sahb.graphqlclient.

ClarenceMG avatar ClarenceMG commented on August 24, 2024

Thank you so much!
I will test the example.

from sahb.graphqlclient.

sahb1239 avatar sahb1239 commented on August 24, 2024

@ClarenceMG Does it work?

from sahb.graphqlclient.

ClarenceMG avatar ClarenceMG commented on August 24, 2024

@sahb1239 your example is not working for me.
Apparently I subscribe but I never receive an answer, so I think the library disconnects very quickly.
I'm using Xamarin iOS 😕

from sahb.graphqlclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.