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

I'm trying to subscribe to this API, but I don't receive any response. These are my classes and this is the subscription #95

Open
ClarenceMG opened this issue Feb 7, 2020 · 6 comments

Comments

@ClarenceMG
Copy link

ClarenceMG commented Feb 7, 2020

ws://snowtooth.moonhighway.com/graphql

I'm using Xamarin iOS.

subscription {
liftStatusChange {
name
capacity
}
}

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

public class Data
{
	public LiftStatusChange LiftStatusChange { get; set; }
}
@chelliwell
Copy link
Contributor

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....

@sahb1239
Copy link
Owner

sahb1239 commented Feb 10, 2020

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.

@ClarenceMG
Copy link
Author

Thank you so much!
I will test the example.

@sahb1239
Copy link
Owner

@ClarenceMG Does it work?

@ClarenceMG
Copy link
Author

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

@ClarenceMG
Copy link
Author

@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 😕

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

3 participants