How to write a schema and Graphql for array output?

I am pretty new in GraphQL. I am trying to get Card details from magento backend for authenticate user. I am not passing any input but directly taking customer id form magento.

Schema.graphqls -

type Mutation { /* Some other queries */ getSavedCards: [GetSavedCardsOutput] @resolver(class: "\\MyModule\\SaveCards\\Model\\Resolver\\GetSavedCards") } type GetSavedCardsOutput { id: String, cardHolderName: String, cardNumber: String, dateExpiryMonth: Int, dateExpiryYear: Int, type: String }

As GetSavedCardsOutput is array which will hold card details (which can be empty array as well) of the users got from third party API.

get-saved-cards.graphql -

mutation { getSavedCards{ id, cardHolderName, cardNumber, dateExpiryMonth, dateExpiryYear, type } }

But when I try to hit this graphql I am getting error.

{#332 +"errors": array:6 [ 0 => {#318 +"message": "Cannot query field "id" on type "GetSavedCardsOutput"." +"extensions": {#321 +"category": "graphql" } +"locations": array:1 [ 0 => {#324 +"line": 3 +"column": 9 } ] } 1 => {#322 +"message": "Cannot query field "cardHolderName" on type "GetSavedCardsOutput"." +"extensions": {#312 +"category": "graphql" } +"locations": array:1 [ 0 => {#319 +"line": 4 +"column": 9 } ] } 2 => {#313 +"message": "Cannot query field "cardNumber" on type "GetSavedCardsOutput"." +"extensions": {#309 +"category": "graphql" } +"locations": array:1 [ 0 => {#308 +"line": 5 +"column": 9 } ] } 3 => {#323 +"message": "Cannot query field "dateExpiryMonth" on type "GetSavedCardsOutput"." +"extensions": {#316 +"category": "graphql" } +"locations": array:1 [ 0 => {#325 +"line": 6 +"column": 9 } ] } 4 => {#326 +"message": "Cannot query field "dateExpiryYear" on type "GetSavedCardsOutput"." +"extensions": {#327 +"category": "graphql" } +"locations": array:1 [ 0 => {#328 +"line": 7 +"column": 9 } ] } 5 => {#329 +"message": "Cannot query field "type" on type "GetSavedCardsOutput"." +"extensions": {#330 +"category": "graphql" } +"locations": array:1 [ 0 => {#331 +"line": 8 +"column": 9 } ] } ] }

I am not getting what exactly goes wrong.

Thanks.

Read Entire Article