Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query with variables return null #1296

Closed
kejoRx opened this issue Mar 22, 2018 · 1 comment
Closed

Query with variables return null #1296

kejoRx opened this issue Mar 22, 2018 · 1 comment

Comments

@kejoRx
Copy link

kejoRx commented Mar 22, 2018

const typeDefs = `
    type Item  {
        id: ID!
        sku: String!
        name: String!
        attribute_set_id: Int!
        price: Float
        status: Int!
        visibility: Int!
        type_id: String!
        created_at: String!
        updated_at: String!
        product_links: [String]
        tier_prices: [Int]
        custom_attributes: [CUSTOM_ATTRIBUTES]
    }
        
    union CUSTOM_ATTRIBUTES = CustomString | CustomArray
    
   type CustomString {
    attribute_code: String
    value: String
  }
  
  type CustomArray {
    attribute_code: String
    value: [String]
    
  } 

  type Query {
    allItems(value: [String]!): [Item]!
    
  }
`;

Resolver func

export const resolvers = {
    Query: {
        allItems: (_, { value }) => getAllLinks().then(result => filter(result, {value: value}))
        //allItems: () => getAllLinks(),

    },

Graphiql query:

query FetchItems($values : [String]!){
  allItems(value : $values){
    id
    name
    custom_attributes{
      __typename
      ... on CustomString{
        attribute_code
        valString: value
      }
      ... on CustomArray{
        attribute_code
        valArray: value
      }
    }
  }
}

Query Variables:

{
  "values": ["3"]
}

Output:

{
  "data": {
    "allItems": []
  }
}

It should return items that have "3" (or any other number) as string in value in typename CustomArray (that's where is category_ids), but it returns null. Why?

This is the first item in api:

{
                "id": 1,
                "name": "Some name",
                "some others" : "that not matter"
                "custom_attributes": [
                    {
                        "attribute_code": "description",
                        "value": "<p>Here's is description</p>"
                    },
                    {
                        "attribute_code": "image",
                        "value": "/m/b/mb01-blue-0.jpg"
                    },
                    {
                        "attribute_code": "small_image",
                        "value": "/m/b/mb01-blue-0.jpg"
                    },
                    {
                        "attribute_code": "thumbnail",
                        "value": "/m/b/mb01-blue-0.jpg"
                    },
                    {
                        "attribute_code": "category_ids",
                        "value": [
                            "3",
                            "4"
                        ]
                    },
                    {
                       "some others" : "that not matter as well"
                    },
                   
                ]
            },
@IvanGoncharov
Copy link
Member

We want to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track bugs and features that affect development.

If you have a question on how to use GraphQL, please post it to Stack Overflow with the tag #graphql.

@kejoRx Please consider posting your question to Stack Overflow.
If you think it's caused by some bug in graphql-js please provide a minimal example with all code involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants