Создание соединения GraphQL из ConnectionBuilder - PullRequest
0 голосов
/ 29 января 2020

Я использую GraphQL. NET (graphql-do tnet) от Joe McBride версия 2.4.0

Я работаю над схемой GraphQL и хочу использовать ConnectionBuilder для создания Соединения между 2 типа (Клиент и Заказ).

Проблема: я не могу использовать установщик в свойстве Connection с типом возврата, вызывающим ConnectionBuilder.Create (), потому что тип возвращаемого значения - ConnectionBuilder, и мне нужно Connection.

Фактически, ни один из методов в ConnectionBuilder не возвращает Connection. На самом деле, ни один метод не возвращает Connection.

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class Order
{
    public int Id { get; set; }
    public string Name { get; set; }
}

// Invoked Connection() in ComplexGraphType class returns a ConnectionBuilder<TNodeType, TSourceType>
var connection = connectionMethod.Invoke(customer, null);

// Give name "OrderConnection" to the newly created connection
connection.GetType().GetMethod("Name").Invoke(connection, new object[] { "OrderConnection" });

// Set newly created connection on customer class
var orderConnection = customer.GetProperty("OrderConnection").GetSetMethod();

TL; DR: как я могу использовать invoke для ConnectionBuilder.Create () с двумя сущностями (Customer и Order) и получить результат типа Connection который будет называться OrderConnection и назначать его, поэтому я могу запросить его, используя следующий запрос:

query {
  customer(id: "1") {
    orderConnection {
      edges {
        node {
          id
        }
      }
    }
  }
}
...