1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS AppSync で可変長引数を取るクエリを書く (JSONで渡す)

1
Last updated at Posted at 2018-04-27

可変長引数を配列で渡せないものだと思っていたら、JSON.stringfy で文字列にしなくても渡すことが出来ました。

Schema

input AttributeTypeInput {
	attribute_type_id: ID!
	max: Float!
	min: Float!
}
type Query {
searchItemsByAttribute( attribute_type_inputs: [AttributeTypeInput]): [Item]
}

query

query searchItem{
  searchItemsByAttribute(
  attribute_type_inputs: [{
    attribute_type_id:  1,
    min: 1,
    max: 10000000000
  }]){
    name
  }
}

request mapping template

"params":{
        "body": {
            "from": 0,
            "size": 50,
            "query":{"bool":{"must":[
            #foreach($attribute_type in $context.arguments.attribute_types) 
            {"term":{"units.attribute_type_id":"${attribute_type.attribute_type_id}"}},
            {"range":{"units.value":{"lte":"${attribute_type.max}","gte":"${attribute_type.min}"}}},
             #end
            ],
            }
                
            }
        }
    }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?