Example #1
0
        public DeviceMutation(IHelpDesk hd)
        {
            Field <DeviceType>(
                "addDevice",
                arguments: new QueryArguments(
                    new QueryArgument <DeviceInputType> {
                Name = "device"
            }
                    ),
                resolve: context =>
            {
                var receivedDevice = context.GetArgument <Device>("device");
                var device         = hd.AddDevice(receivedDevice);
                return(device);
            });

            Field <DeviceType>(
                "updateDevice",
                arguments: new QueryArguments(
                    new QueryArgument <DeviceInputType> {
                Name = "device"
            }
                    ),
                resolve: context =>
            {
                var receivedDevice = context.GetArgument <Device>("device");
                var devices        = hd.AllDevices.ToArray();
                var device         = Array.Find(devices, d => d.Id == receivedDevice.Id);
                device.IsOnline    = receivedDevice.IsOnline;

                hd.UpdateDevice(device);

                return(device);
            });
        }
Example #2
0
 public DeviceQuery(IHelpDesk hd)
 {
     Field <ListGraphType <DeviceType> >(
         "devices",
         resolve: context =>
     {
         return(hd.AllDevices.Take(100));
     }
         );
 }
        public DeviceSubscriptions(IHelpDesk hd)
        {
            _hd = hd;

            AddField(new EventStreamFieldType
            {
                Name       = "deviceAdded",
                Type       = typeof(DeviceType),
                Resolver   = new FuncFieldResolver <Device>(ResolveDevice),
                Subscriber = new EventStreamResolver <Device>(Subscribe)
            });

            AddField(new EventStreamFieldType
            {
                Name      = "deviceStatusChanged",
                Arguments = new QueryArguments(
                    new QueryArgument <NonNullGraphType <BooleanGraphType> > {
                    Name = "isOnline"
                }
                    ),
                Type       = typeof(DeviceType),
                Resolver   = new FuncFieldResolver <Device>(ResolveDevice),
                Subscriber = new EventStreamResolver <Device>(SubscribeByStatus)
            });

            AddField(new EventStreamFieldType
            {
                Name      = "deviceUpdated",
                Arguments = new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                    Name = "id"
                },
                    new QueryArgument <StringGraphType> {
                    Name = "deviceJson"
                }
                    ),
                Type       = typeof(DeviceType),
                Resolver   = new FuncFieldResolver <Device>(ResolveDevice),
                Subscriber = new EventStreamResolver <Device>(deviceUpdatedSubscribe)
            });
        }
Example #4
0
 public DeviceSchema(IHelpDesk hd)
 {
     Query        = new DeviceQuery(hd);
     Mutation     = new DeviceMutation(hd);
     Subscription = new DeviceSubscriptions(hd);
 }