Esempio n. 1
0
        protected override void Configure(IObjectTypeDescriptor descriptor)
        {
            descriptor.ExtendQuery();
            descriptor.Field("filesystem")
            .Argument("directoryPath",
                      a => a.Type <OSDirectoryPathType>()
                      .Description("The path to explore. If this is null, returns a listing of drives on Windows, " +
                                   "or the root directory on a Unix-like system."))
            .Resolver(context => {
                var path = context.Argument <DirectoryInfo>("directoryPath");
                if ((path == null) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    return(DriveInfo.GetDrives());
                }
                if ((path == null) &&
                    (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
                     RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
                     RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)))
                {
                    return(new DirectoryInfo("/"));
                }

                if (path?.Exists ?? false)
                {
                    return(path);
                }
                return(null);
            })
            .Type <OSDirectoryContentsInterface>()
            .Description("Provides normalized OS-dependent filesystem access." +
                         "Returns null if the specified path does not exist.");
        }
Esempio n. 2
0
 protected override void Configure(IObjectTypeDescriptor descriptor)
 {
     descriptor.ExtendQuery();
     descriptor.Field("stone")
     .Description("Provides access to Stone platform and controller definitions.")
     .Type <NonNullType <StoneProviderType> >()
     .Resolver(ctx => ctx.SnowflakeService <IStoneProvider>());
 }
Esempio n. 3
0
 protected override void Configure(IObjectTypeDescriptor descriptor)
 {
     descriptor.ExtendQuery();
     descriptor.Field("electronPackages")
     .Description("All loaded Electron ASAR theme packages.")
     .Resolve(ctx => ctx.SnowflakeService <IElectronPackageProvider>().Interfaces)
     .Type <NonNullType <ListType <NonNullType <ElectronPackageType> > > >();
 }
Esempio n. 4
0
 protected override void Configure(IObjectTypeDescriptor descriptor)
 {
     descriptor.ExtendQuery();
     descriptor.Field("devices")
     .Type <NonNullType <ListType <NonNullType <InputDeviceType> > > >()
     .Description("Provides access to input devices on the system.")
     .Resolve(context =>
     {
         var input = context.SnowflakeService <IDeviceEnumerator>();
         return(input.QueryConnectedDevices());
     });
 }
Esempio n. 5
0
 protected override void Configure(IObjectTypeDescriptor descriptor)
 {
     descriptor.ExtendQuery();
     descriptor.Field("gameEmulation")
     .Description("Provides access to information about currently queued game emulation instances. Returns null if the instance does not exist.")
     .Argument("instanceId", arg => arg.Type <NonNullType <UuidType> >()
               .Description("The `instanceId` of the game emulation instance that is used to query the game emulation state."))
     .Resolver(ctx =>
     {
         var guid = ctx.Argument <Guid>("instanceId");
         ctx.GetGameCache().TryGetValue(guid, out var gameEmulation);
         return(gameEmulation);
     })
     .Type <GameEmulationType>();
 }
Esempio n. 6
0
        protected override void Configure(IObjectTypeDescriptor descriptor)
        {
            descriptor.ExtendQuery();

            descriptor
            .Field("games")
            .Type <NonNullType <ListType <NonNullType <GameType> > > >()
            .Argument("excludeDeleted", arg => arg.Type <BooleanType>()
                      .Description("Exclude games that have been marked as deleted. " +
                                   "Setting this to true is shorthand for retrieving games with the game_deleted metadata not set to \"true\".")
                      .DefaultValue(true))
            .AddFilterArguments <GameRecordQueryFilterInputType>()
            .Use(next => context =>
            {
                IValueNode valueNode = context.ArgumentValue <IValueNode>("where");
                bool excludeDeleted  = context.ArgumentValue <bool>("excludeDeleted");
                Expression <Func <IGameRecordQuery, bool> > excludeDeletedQuery = r =>
                                                                                  !r.Metadata.Any(r => r.MetadataKey == GameMetadataKeys.Deleted && r.MetadataValue == "true");

                var queryBuilder = context.SnowflakeService <IGameLibrary>();

                if (valueNode is null || valueNode is NullValueNode)
                {
                    if (!excludeDeleted)
                    {
                        context.Result = queryBuilder
                                         .GetAllGames()
                                         .ToList();
                    }
                    else
                    {
                        context.Result = queryBuilder.QueryGames(excludeDeletedQuery);
                    }
                    return(next.Invoke(context));
                }

                if (context.Field.Arguments["where"].Type is InputObjectType iot && iot is IFilterInputType)
                {
                    var filter = new QueryableFilterVisitorContext(iot, typeof(IGameRecordQuery), context.GetTypeConverter(), true);
                    QueryableFilterVisitor.Default.Visit(valueNode, filter);

                    var expr = filter.CreateFilter <IGameRecordQuery>();

                    if (!excludeDeleted)
                    {
                        context.Result = queryBuilder.QueryGames(expr).ToList();
                    }
                    else
                    {
                        // Invoke works fine here. We could use a expression tree visitor, but
                        // that is a lot more code than just using Invoke.
                        ParameterExpression param = expr.Parameters[0];
                        var combinedBody          = Expression.AndAlso(
                            expr.Body,
                            Expression.Invoke(excludeDeletedQuery, param)
                            );
                        var combinedLambda = Expression.Lambda <Func <IGameRecordQuery, bool> >(combinedBody, param);
                        context.Result     = queryBuilder.QueryGames(combinedLambda).ToList();
                    }
                }
                return(next.Invoke(context));
            })
            .UsePaging <GameType>();
        }