コード例 #1
0
        private async Task LoadGraphQLDocumentsAsync(
            string path,
            ClientGenerator generator,
            ICollection <HCError> errors)
        {
            Dictionary <string, SchemaFile> schemaConfigs =
                (await Configuration.LoadConfig(path)).Schemas.ToDictionary(t => t.Name);

            foreach (DocumentInfo document in await GetGraphQLFiles(path, errors))
            {
                if (document.Kind == DocumentKind.Query)
                {
                    generator.AddQueryDocument(
                        IOPath.GetFileNameWithoutExtension(document.FileName),
                        document.FileName,
                        document.Document);
                }
                else
                {
                    string name = IOPath.GetFileNameWithoutExtension(
                        document.FileName);

                    if (schemaConfigs.TryGetValue(
                            IOPath.GetFileName(document.FileName),
                            out SchemaFile file))
                    {
                        name = file.Name;
                    }

                    generator.AddSchemaDocument(
                        name,
                        document.Document);
                }
            }
        }
コード例 #2
0
        private async Task LoadGraphQLDocumentsAsync(
            string path,
            ClientGenerator generator,
            ICollection <HCError> errors)
        {
            Configuration?configuration = await Configuration.LoadConfig(path);

            if (configuration is null)
            {
                throw new InvalidOperationException(
                          "The configuration does not exist.");
            }

            if (configuration.Schemas is null)
            {
                throw new InvalidOperationException(
                          "The configuration has no schemas defined.");
            }

            Dictionary <string, SchemaFile> schemas =
                configuration.Schemas.Where(t => t.Name != null)
                .ToDictionary(t => t.Name !);

            foreach (DocumentInfo document in await GetGraphQLFiles(path, errors))
            {
                if (document.Kind == DocumentKind.Query)
                {
                    generator.AddQueryDocument(
                        IOPath.GetFileNameWithoutExtension(document.FileName),
                        document.FileName,
                        document.Document);
                }
                else
                {
                    string name = IOPath.GetFileNameWithoutExtension(
                        document.FileName);

                    if (schemas.TryGetValue(
                            IOPath.GetFileName(document.FileName),
                            out SchemaFile? file))
                    {
                        name = file.Name !;
                    }

                    generator.AddSchemaDocument(
                        name,
                        document.Document);
                }
            }
        }