如何修改graphql-ruby中子字段的上下文?

问题描述

我有这样的查询

query {
  organizations {
    id
    name
    itemA {
      fieldA
      fieldB
    }
  }
}

返回

"data": {
  "organizations": [
    {
      "id": 123,"name": "first org","itemA": {
        "fieldA": "some value A","fieldB": "other value B",}
    },{
      "id": 321,"name": "other org","itemA": {
        "fieldA": "other value A","fieldB": "value B",}
    }
  ]
}

一个用户可以访问多个组织,但每个组织的访问权限不同。

fieldAfieldB 被解析以验证访问权限时,我需要有 organization.id。

我尝试在解析器中将 context.merge_scoped!(organiozation_id: org.id) 用于返回单个组织的字段。 看起来它可以满足我的需要,子字段在 context 中收到了正确的值,但我不确定。没有关于该方法和一般 scoped_context 的文档。

另外,如果 scoped_context 是我所需要的,我该如何为项目列表设置它?


UPD:示例查询

query {
  organizations { // I need to pass item of this list to resolver of ItemA
    someModel{
      otherModel {
        itemA // access depened on organization`
      }
    }
  }
}

解决方法

我不能 100% 确定我遇到了您的问题,但我认为您需要的内容对于 GQL 应该是“透明的”。

您需要两件事才能正确列出组织的“项目”:1. 哪个组织和 2. 谁在询问:

output = tf.keras.layers.Dense(units=NUM_OUTPUTS)(dropout_dense1)
output_reg = tf.keras.layers.Activation('relu')(output)

# Define ActivityRegularization layer
reg_output = tf.keras.layers.ActivityRegularization(l1=0.001,l2=0.001)

# Apply ActivityRegularization layer to the non-weight directly layer that you want 
output_reg = reg_output(output_reg)

other_layer = tf.keras.layers.Dense(units=NUM)(output_reg)
final_output = tf.keras.layers.Activation('relu')(other_layer)

model = tf.keras.Model(input,final_output)

如您所见,似乎根本没有理由操纵上下文。 (除非我完全没有抓住重点,所以请随时修改您的问题以澄清)。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...