while sending array of enum i got Error from typescript graphql nestjs api

while sending array of enum i got Error from typescript graphql nestjs api


0

Question

My Stack: BE NestJS, graphQL(code first approach), prisma / FE NextJS

Problem:

For my model "Conventions" all fields working to send from FE to GraphQL NestJS API, but one field uses an array of an enum Called "ConGenres" i am not able to figure out why it doesnt work this way:

FE (NextJs)

import { ConventionCreateInput } from '@/generated/graphql';
(...)

    const onSubmit = async (data:any) => {
        data.genres = [
            ConGenres.Fantasy,
            ConGenres.Crime,
         ]
        gqlReq.conventionCreate({data}),
    };

(...)

Server Error Response:

{
    "errors": [
        {
            "message": "Variable "$data" got invalid value ["fantasy", "crime"] at "data.genres"; Field "set" of required type "[ConGenres!]!" was not provided.",
            "locations": [
                {
                    "line": 1,
                    "column": 27
                }
            ],
            "extensions": {
                "code": "BAD_USER_INPUT",
                "stacktrace": [
                    "GraphQLError: Field "set" of required type "[ConGenres!]!" was not provided.",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:108:13)",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:117:34)",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:49:14)",
                    "    at coerceInputValue (/api/node_modules/graphql/utilities/coerceInputValue.js:32:10)",
                    "    at coerceVariableValues (/api/node_modules/graphql/execution/values.js:132:69)",
                    "    at getVariableValues (/api/node_modules/graphql/execution/values.js:45:21)",
                    "    at buildExecutionContext (/api/node_modules/graphql/execution/execute.js:280:63)",
                    "    at execute (/api/node_modules/graphql/execution/execute.js:116:22)",
                    "    at executeIncrementally (/api/node_modules/@apollo/server/src/incrementalDeliveryPolyfill.ts:114:17)",
                    "    at processTicksAndRejections (node:internal/process/task_queues:95:5)"
                ]
            }
        },
        {
            "message": "Variable "$data" got invalid value ["fantasy", "crime"] at "data.genres"; Field "0" is not defined by type "ConventionCreategenresInput".",
            "locations": [
                {
                    "line": 1,
                    "column": 27
                }
            ],
            "extensions": {
                "code": "BAD_USER_INPUT",
                "stacktrace": [
                    "GraphQLError: Field "0" is not defined by type "ConventionCreategenresInput".",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:134:11)",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:117:34)",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:49:14)",
                    "    at coerceInputValue (/api/node_modules/graphql/utilities/coerceInputValue.js:32:10)",
                    "    at coerceVariableValues (/api/node_modules/graphql/execution/values.js:132:69)",
                    "    at getVariableValues (/api/node_modules/graphql/execution/values.js:45:21)",
                    "    at buildExecutionContext (/api/node_modules/graphql/execution/execute.js:280:63)",
                    "    at execute (/api/node_modules/graphql/execution/execute.js:116:22)",
                    "    at executeIncrementally (/api/node_modules/@apollo/server/src/incrementalDeliveryPolyfill.ts:114:17)",
                    "    at processTicksAndRejections (node:internal/process/task_queues:95:5)"
                ]
            }
        },
        {
            "message": "Variable "$data" got invalid value ["fantasy", "crime"] at "data.genres"; Field "1" is not defined by type "ConventionCreategenresInput".",
            "locations": [
                {
                    "line": 1,
                    "column": 27
                }
            ],
            "extensions": {
                "code": "BAD_USER_INPUT",
                "stacktrace": [
                    "GraphQLError: Field "1" is not defined by type "ConventionCreategenresInput".",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:134:11)",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:117:34)",
                    "    at coerceInputValueImpl (/api/node_modules/graphql/utilities/coerceInputValue.js:49:14)",
                    "    at coerceInputValue (/api/node_modules/graphql/utilities/coerceInputValue.js:32:10)",
                    "    at coerceVariableValues (/api/node_modules/graphql/execution/values.js:132:69)",
                    "    at getVariableValues (/api/node_modules/graphql/execution/values.js:45:21)",
                    "    at buildExecutionContext (/api/node_modules/graphql/execution/execute.js:280:63)",
                    "    at execute (/api/node_modules/graphql/execution/execute.js:116:22)",
                    "    at executeIncrementally (/api/node_modules/@apollo/server/src/incrementalDeliveryPolyfill.ts:114:17)",
                    "    at processTicksAndRejections (node:internal/process/task_queues:95:5)"
                ]
            }
        }
    ]
}

schema.prisma

model Convention {
(...)
    genres            ConGenres[]
(...)
}

enum ConGenres {
  fantasy
  crime
   (...)
}

Share
Improve this question


Load 6 more related questions


Show fewer related questions

0

Reset to default



Browse other questions tagged

or ask your own question.

Leave a Reply

Your email address will not be published. Required fields are marked *