question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

YAML schema is incorrect

See original GitHub issue

Describe the bug

When using the VSCode (version 1.70 YAML extension redhat.vscode-yaml (version 1.9.1), it considers the config.schema.json as invalid due to the use of string[] as value in the type field.

Schema 'GraphQL Code Generator (config.schema.json)' is not valid:
/definitions/TypeGraphQLPluginConfig/properties/decorateTypes/type : must be equal to one of the allowed values
/definitions/TypeGraphQLPluginConfig/properties/decorateTypes/type : must be array
/definitions/TypeGraphQLPluginConfig/properties/decorateTypes/type : must match a schema in anyOfYAML(768)
    "TypeGraphQLPluginConfig": {
      "type": "object",
      "properties": {
        "decoratorName": {
          "$ref": "#/definitions/Partial_1",
          "description": "allow overriding of TypeGraphQL decorator types\nDefault value: \"{ type: 'ObjectType', interface: 'InterfaceType', arguments: 'ArgsType', field: 'Field', input: 'InputType' }\""
        },
        "decorateTypes": {
          "description": "Specifies the objects that will have TypeGraphQL decorators prepended to them, by name. Non-matching types will still be output, but without decorators. If not set, all types will be decorated.",
          "type": "string[]"
        },
image

Reference https://www.graphql-code-generator.com/docs/config-reference/codegen-config


Additionally, when I overrode it and fixed that string[] locally, it had another issue where top level config values had to be objects:

image

Which is exactly what the example docs say they support.

    "__type": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/T"
      }
    },
    "T": {
      "type": "object"
    },
    "Types.PluginConfig": {
      "$ref": "#/definitions/__type"
    },

Your Example Website or App

https://www.graphql-code-generator.com/config.schema.json

Steps to Reproduce the Bug or Issue

I don’t have a link to a repo because I don’t think it is relevant.

Try to create a codegen.yml file in VSCode while using the YAML extension.

Expected behavior

The schema to be valid.

Screenshots or Videos

image image

Platform

VSCode output: Version: 1.70.0 (Universal) Commit: da76f93349a72022ca4670c1b84860304616aaa2 Date: 2022-08-04T04:38:55.829Z (5 days ago) Electron: 18.3.5 Chromium: 100.0.4896.160 Node.js: 16.13.2 V8: 10.0.139.17-electron.0 OS: Darwin arm64 21.6.0

YAML extension: 1.9.1

Also tested on YAML extension 1.7.0 with the same results.

Codegen Config File

Doesn’t actually matter what the YML is, so here are the first few lines:

config:
  avoidOptionals:
    field: true
    inputValue: false
    object: true
    defaultValue: true
  # Use Unions instead of Enums
  enumsAsTypes: true

Additional context

https://www.graphql-code-generator.com/config.schema.json Search for string[]

Search for “T”

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MariaSolOscommented, Aug 13, 2022

This can be “fixed” by removing all traces of TypeGraphQLPluginConfig from the schema, so it seems to be particularly caused by that plugin. Any actually valid YAML file not using that plugin will now be valid.

diff --git b/client-apps/config.schema.json a/client-apps/config.schema.json
index 67b195122..04b7e8294 100644
--- b/client-apps/config.schema.json
+++ a/client-apps/config.schema.json
@@ -984,169 +984,6 @@
         "federation": { "type": "boolean" }
       }
     },
-    "TypeGraphQLPluginConfig": {
-      "type": "object",
-      "properties": {
-        "decoratorName": {
-          "$ref": "#/definitions/Partial_1",
-          "description": "allow overriding of TypeGraphQL decorator types\nDefault value: \"{ type: 'ObjectType', interface: 'InterfaceType', arguments: 'ArgsType', field: 'Field', input: 'InputType' }\""
-        },
-        "decorateTypes": {
-          "description": "Specifies the objects that will have TypeGraphQL decorators prepended to them, by name. Non-matching types will still be output, but without decorators. If not set, all types will be decorated.",
-          "type": "string[]"
-        },
-        "avoidOptionals": {
-          "description": "This will cause the generator to avoid using TypeScript optionals (`?`) on types,\nso the following definition: `type A { myField: String }` will output `myField: Maybe<string>`\ninstead of `myField?: Maybe<string>`.\nDefault value: \"false\"",
-          "anyOf": [{ "$ref": "#/definitions/AvoidOptionalsConfig" }, { "type": "boolean" }]
-        },
-        "constEnums": {
-          "description": "Will prefix every generated `enum` with `const`, you can read more about const enums here: https://www.typescriptlang.org/docs/handbook/enums.html.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "enumsAsTypes": {
-          "description": "Generates enum as TypeScript `type` instead of `enum`. Useful if you wish to generate `.d.ts` declaration file instead of `.ts`\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "numericEnums": {
-          "description": "Controls whether to preserve typescript enum values as numbers\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "futureProofEnums": {
-          "description": "This option controls whether or not a catch-all entry is added to enum type definitions for values that may be added in the future.\nThis is useful if you are using `relay`.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "futureProofUnions": {
-          "description": "This option controls whether or not a catch-all entry is added to union type definitions for values that may be added in the future.\nThis is useful if you are using `relay`.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "enumsAsConst": {
-          "description": "Generates enum as TypeScript `const assertions` instead of `enum`. This can even be used to enable enum-like patterns in plain JavaScript code if you choose not to use TypeScript’s enum construct.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "onlyEnums": {
-          "description": "This will cause the generator to emit types for enums only.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "onlyOperationTypes": {
-          "description": "This will cause the generator to emit types for operations only (basically only enums and scalars).\nInteracts well with `preResolveTypes: true`\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "immutableTypes": {
-          "description": "Generates immutable types by adding `readonly` to properties and uses `ReadonlyArray`.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "maybeValue": {
-          "description": "Allow to override the type value of `Maybe`.\nDefault value: \"T | null\"",
-          "type": "string"
-        },
-        "inputMaybeValue": {
-          "description": "Allow to override the type value of `Maybe` for input types and arguments.\nThis is useful in case you want to differentiate between the wrapper of input and output types.\nBy default, this type just refers to `Maybe` type, but you can override it's definition.\nDefault value: \"Maybe<T>\"",
-          "type": "string"
-        },
-        "noExport": {
-          "description": "Set to `true` in order to generate output without `export` modifier.\nThis is useful if you are generating `.d.ts` file and want it to be globally available.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "disableDescriptions": {
-          "description": "Set the value to `true` in order to disable all description generation.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "useImplementingTypes": {
-          "description": "When a GraphQL interface is used for a field, this flag will use the implementing types, instead of the interface itself.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "wrapEntireFieldDefinitions": {
-          "type": "boolean",
-          "description": "Set to `true` in order to wrap field definitions with `EntireFieldWrapper`.\nThis is useful to allow return types such as Promises and functions for fields.\nDiffers from `wrapFieldDefinitions` in that this wraps the entire field definition if i.e. the field is an Array, while\n`wrapFieldDefinitions` will wrap every single value inside the array.\nDefault value: \"false\""
-        },
-        "entireFieldWrapperValue": {
-          "type": "string",
-          "description": "Allow to override the type value of `EntireFieldWrapper`. This wrapper applies outside of Array and Maybe\nunlike `fieldWrapperValue`, that will wrap the inner type.\nDefault value: \"T | Promise<T> | (() => T | Promise<T>)\""
-        },
-        "allowEnumStringTypes": { "description": "Allow using enum string values directly.", "type": "boolean" },
-        "addUnderscoreToArgsType": {
-          "description": "Adds `_` to generated `Args` types in order to avoid duplicate identifiers.",
-          "type": "boolean"
-        },
-        "enumValues": {
-          "$ref": "#/definitions/EnumValuesMap",
-          "description": "Overrides the default value of enum values declared in your GraphQL schema.\nYou can also map the entire enum to an external type by providing a string that of `module#type`."
-        },
-        "declarationKind": {
-          "description": "Overrides the default output for various GraphQL elements.",
-          "anyOf": [
-            { "$ref": "#/definitions/DeclarationKindConfig" },
-            { "enum": ["abstract class", "class", "interface", "type"], "type": "string" }
-          ]
-        },
-        "enumPrefix": {
-          "description": "Allow you to disable prefixing for generated enums, works in combination with `typesPrefix`.\nDefault value: \"true\"",
-          "type": "boolean"
-        },
-        "fieldWrapperValue": {
-          "description": "Allow you to add wrapper for field type, use T as the generic value. Make sure to set `wrapFieldDefinitions` to `true` in order to make this flag work.\nDefault value: \"T\"",
-          "type": "string"
-        },
-        "wrapFieldDefinitions": {
-          "description": "Set to `true` in order to wrap field definitions with `FieldWrapper`.\nThis is useful to allow return types such as Promises and functions.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "ignoreEnumValuesFromSchema": {
-          "description": "This will cause the generator to ignore enum values defined in GraphQLSchema\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "directiveArgumentAndInputFieldMappings": {
-          "$ref": "#/definitions/DirectiveArgumentAndInputFieldMappings",
-          "description": "Replaces a GraphQL scalar with a custom type based on the applied directive on an argument or input field.\n\nYou can use both `module#type` and `module#namespace#type` syntax.\nWill NOT work with introspected schemas since directives are not exported.\nOnly works with directives on ARGUMENT_DEFINITION or INPUT_FIELD_DEFINITION.\n\n**WARNING:** Using this option does only change the type definitions.\n\nFor actually ensuring that a type is correct at runtime you will have to use schema transforms (e.g. with [@graphql-tools/utils mapSchema](https://graphql-tools.com/docs/schema-directives)) that apply those rules!\nOtherwise, you might end up with a runtime type mismatch which could cause unnoticed bugs or runtime errors.\n\nPlease use this configuration option with care!"
-        },
-        "directiveArgumentAndInputFieldMappingTypeSuffix": {
-          "description": "Adds a suffix to the imported names to prevent name clashes.",
-          "type": "string"
-        },
-        "strictScalars": {
-          "description": "Makes scalars strict.\n\nIf scalars are found in the schema that are not defined in `scalars`\nan error will be thrown during codegen.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "defaultScalarType": {
-          "description": "Allows you to override the type that unknown scalars will have.\nDefault value: \"any\"",
-          "type": "string"
-        },
-        "scalars": {
-          "$ref": "#/definitions/ScalarsMap",
-          "description": "Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type."
-        },
-        "namingConvention": {
-          "$ref": "#/definitions/NamingConvention",
-          "description": "Allow you to override the naming convention of the output.\nYou can either override all namings, or specify an object with specific custom naming convention per output.\nThe format of the converter must be a valid `module#method`.\nAllowed values for specific output are: `typeNames`, `enumValues`.\nYou can also use \"keep\" to keep all GraphQL names as-is.\nAdditionally, you can set `transformUnderscore` to `true` if you want to override the default behavior,\nwhich is to preserve underscores.\n\nAvailable case functions in `change-case-all` are `camelCase`, `capitalCase`, `constantCase`, `dotCase`, `headerCase`, `noCase`, `paramCase`, `pascalCase`, `pathCase`, `sentenceCase`, `snakeCase`, `lowerCase`, `localeLowerCase`, `lowerCaseFirst`, `spongeCase`, `titleCase`, `upperCase`, `localeUpperCase` and `upperCaseFirst`\n[See more](https://github.com/btxtiger/change-case-all)\nDefault value: \"change-case-all#pascalCase\""
-        },
-        "typesPrefix": { "description": "Prefixes all the generated types.\nDefault value: \"\"", "type": "string" },
-        "typesSuffix": { "description": "Suffixes all the generated types.\nDefault value: \"\"", "type": "string" },
-        "skipTypename": {
-          "description": "Does not add `__typename` to the generated types, unless it was specified in the selection set.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "nonOptionalTypename": {
-          "description": "Automatically adds `__typename` field to the generated types, even when they are not specified\nin the selection set, and makes it non-optional\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "useTypeImports": {
-          "type": "boolean",
-          "description": "Will use `import type {}` rather than `import {}` when importing only types. This gives\ncompatibility with TypeScript's \"importsNotUsedAsValues\": \"error\" option\nDefault value: \"false\""
-        },
-        "dedupeFragments": {
-          "description": "Removes fragment duplicates for reducing data transfer.\nIt is done by removing sub-fragments imports from fragment definition\nInstead - all of them are imported to the Operation node.\nDefault value: \"false\"",
-          "type": "boolean"
-        },
-        "inlineFragmentTypes": {
-          "$ref": "#/definitions/InlineFragmentTypeOptions",
-          "description": "Whether fragment types should be inlined into other operations.\n\"inline\" is the default behavior and will perform deep inlining fragment types within operation type definitions.\n\"combine\" is the previous behavior that uses fragment type references without inlining the types (and might cause issues with deeply nested fragment that uses list types).\nDefault value: \"inline\""
-        },
-        "emitLegacyCommonJSImports": {
-          "description": "Emit legacy common js imports.\nDefault it will be `true` this way it ensure that generated code works with [non-compliant bundlers](https://github.com/dotansimha/graphql-code-generator/issues/8065).\nDefault value: \"true\"",
-          "type": "boolean"
-        }
-      }
-    },
     "TypeScriptFilesModulesPluginConfig": {
       "description": "This plugin generates TypeScript typings for `.graphql` files containing GraphQL documents, which later on can be consumed using [`graphql-tag/loader`](https://github.com/apollographql/graphql-tag#webpack-preprocessing-with-graphql-tagloader) or use `string` types if you will use the operations as raw strings, and get type-check and type-safety for your imports. This means that any time you import objects from `.graphql` files, your IDE will provide auto-complete.\n\nThis plugin also handles `.graphql` files containing multiple GraphQL documents, and name the imports according to the operation name.\n\n> ⚠ Fragments are not generated with named imports, only as default imports, due to `graphql-tag/loader` behavior.",
       "type": "object",
@@ -3678,12 +3515,6 @@
           "if": { "properties": { "plugins": { "contains": { "type": "string", "const": "schema-ast" } } } },
           "then": { "properties": { "config": { "$ref": "#/definitions/SchemaASTConfig" } } }
         },
-        {
-          "if": {
-            "properties": { "plugins": { "contains": { "type": "string", "const": "typescript-type-graphql" } } }
-          },
-          "then": { "properties": { "config": { "$ref": "#/definitions/TypeGraphQLPluginConfig" } } }
-        },
         {
           "if": {
             "properties": {
@@ -3874,7 +3705,6 @@
         "c-sharp": { "$ref": "#/definitions/CSharpResolversPluginRawConfig" },
         "c-sharp-operations": { "$ref": "#/definitions/CSharpOperationsRawPluginConfig" },
         "schema-ast": { "$ref": "#/definitions/SchemaASTConfig" },
-        "typescript-type-graphql": { "$ref": "#/definitions/TypeGraphQLPluginConfig" },
         "typescript-graphql-files-modules": { "$ref": "#/definitions/TypeScriptFilesModulesPluginConfig" },
         "named-operations-object": { "$ref": "#/definitions/NamedOperationsObjectPluginConfig" },
         "typescript-graphql-request": { "$ref": "#/definitions/RawGraphQLRequestPluginConfig" },
@@ -4165,14 +3995,6 @@
             },
             "schema-ast": { "additionalProperties": false, "$ref": "#/definitions/SchemaASTConfig" },
             "@graphql-codegen/schema-ast": { "additionalProperties": false, "$ref": "#/definitions/SchemaASTConfig" },
-            "typescript-type-graphql": {
-              "additionalProperties": false,
-              "$ref": "#/definitions/TypeGraphQLPluginConfig"
-            },
-            "@graphql-codegen/typescript-type-graphql": {
-              "additionalProperties": false,
-              "$ref": "#/definitions/TypeGraphQLPluginConfig"
-            },
             "typescript-graphql-files-modules": {
               "additionalProperties": false,
               "$ref": "#/definitions/TypeScriptFilesModulesPluginConfig"

I don’t think this is an acceptable workaround since it requires to have the schema locally…

1reaction
bbughcommented, Aug 13, 2022

I created a PR for this here: https://github.com/dotansimha/graphql-code-generator/pull/8233

The problem was @type was specified in the JSDoc (and not in any of the other working string[] places), which overrides the type that typescript-schema-generator uses to generate the schema.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uses the wrong schema, even when yaml.schemas is set #397
in yaml.schemas and the extension recognizes that the schema does not exist, so it is receiving the proper schema from settings.json !
Read more >
YAML Schema Validation reports incorrect errors for if conditions
For an Azure Devops pipeline where there is a valid condition (e.g. it runs correctly) it is reporting a validation error in the...
Read more >
flutter - yaml extension error ( Incorrect type. Expected "string ...
The YAML extension is using an incorrect schema to validate your YAML file. Ensure that: your file does contain a correct ...
Read more >
Incorrect YAML Schema validation error : IDEA-298854
See screenshot. This yaml is valid and works during runtime. The value does start with ssh which is what the error msg says...
Read more >
json-schema-validator/no-invalid
The following custom blocks will try to test if it matches with the virtual filenames. <i18n lang="yaml"> # ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found