0

I was trying to replicate the solution given for this question about the same thing. I did all that was described and my implementation looks like this:

Schema:

type Factura @collection(name: "facturas") {
  number: String! @unique
  date: Date!
  due: Date!
  user: String!
  agent: Agent! @relation
  // More unrelated fields...
}

type query {
  facturasByDateRange(before: Date, after: Date): [Factura!]!
    @resolver(name: "facturas_range", paginated: true)
}

UDF:

Query(
  Lambda(
    ["before", "after", "size", "afterCursor", "beforeCursor"],
    Map(
      Paginate(
        Range(Match(Index("facturas_by_date")), Var("before"), Var("after"))
      ),
      Lambda(["date", "ref"], Let({ factura: Get(Var("ref")) }, Var("factura")))
    )
  )
)

I created de corresponding index and populated the database with a couple of items. Note that I chose to go with the resolver pagination parameter set to true, in contrast to the last part to the answer I cited.

I can test the function via the Shell, and it works well... or at least returns the right data: enter image description here

But, what I try the query via graphQL, it returns an empty array! enter image description here

what could be happening??

Complete Schema:

#################### Accounts and centers ####################
type Account @collection(name: "accounts") {
  name: String!
  code: String! @unique
  imputable: Boolean!
  balance: Boolean!
  active: Boolean!
  facturas: [Factura] @relation
}

type Center @collection(name: "centros") {
  code: String! @unique
  name: String!
  active: Boolean!
  facturas: [Factura] @relation
}

#################### Documents ####################

type Detail {
  # Centro y cuenta son solo strings, ya que se usan solo para representar en UI
  centro: String!
  cuenta: String!
  desc: String!
  imponible: Int!
  import: Boolean!
  origin: String!
  q: Int!
  totEx: Int!
  tot5: Int!
  tot10: Int!
  factura: Factura! @relation
}

type Factura @collection(name: "facturas") {
  number: String! @unique
  date: Date!
  due: Date!
  printed: Boolean!
  state: String!
  pay: String!
  user: String!
  agent: Agent! @relation
  client: Client! @relation
  currency: String!
  exchange: Int!
  totEx: Int!
  tot5: Int!
  tot10: Int!
  tot: Int!
  totG: Int!
  tax5: Int!
  tax10: Int!
  centers: [Center] @relation
  accounts: [Account] @relation
  details: [Detail!] @relation
}

type Numbering @collection(name: "numbering") {
  suc: Int!
  boca: Int!
  from: Int!
  to: Int!
  last: Int!
  type: String!
  curr: String!
  number: Int!
  start: Date!
  end: Date!
  state: Boolean!
  tag: String
  comm: String
}

#################### Usuarios y personas ####################

type Client @collection(name: "clients") {
  name: String!
  ruc: String! @unique
  ret: Boolean!
  address: String!
  city: String!
  country: String!
  ext: Boolean!
  email: String
  tel: String!
  fax: String
  contact: String
  facturas: [Factura] @relation
}

type Agent @collection(name: "agents") {
  name: String!
  email: String
  tel: String
  ci: String @unique
  facturas: [Factura] @relation
}

type Query {
  # Accounts
  allAccounts: [Account!]! @index(name: "all_accounts")
  getAccount(code: String!): Account
  activeAccounts(active: Boolean!): [Account!]! @index(name: "active_accounts")
  impAccounts(active: Boolean!, imputable: Boolean!): [Account!]!
    @index(name: "imp_accounts")
  # Centers
  allCenters: [Center!]! @index(name: "all_centers")
  activeCenters(active: Boolean!): [Center!]! @index(name: "active_centers")
  # Clients
  allClients: [Client!]! @index(name: "all_clients")
  # Numbering
  allNumbering: [Numbering!]! @index(name: "all_numbering")
  lastNumbering(type: String!, tag: String!, state: Boolean!): [Numbering!]!
    @index(name: "last_numbering")
  # Facturas
  allFacturas: [Factura!]! @index(name: "all_facturas")
  facturasByDateRange(before: Date, after: Date): [Factura!]!
    @resolver(name: "facturas_range", paginated: true)
}
Danf
  • 1,409
  • 2
  • 21
  • 39
  • Can you share the complete schema? The one you initially included results in an error when attempting to import: `Target type 'Factura' has no field that can be used in the relationship with the type 'query'. (line 9, column 3): facturasByDateRange(before: Date, after: Date): [Factura!]!` (and that's after removing the relation to the unspecified Agent type). – eskwayrd Apr 16 '21 at 18:22
  • I added the complete schema, and it should work... But I tried the fragment I shared originally and have the same problem you mention. I have no idea why! – Danf Apr 16 '21 at 19:56
  • I just replicated exactly what was done in the answer to the question I mentioned, with the poster's schema, and it works fine. Must be some problem with my schema then... – Danf Apr 17 '21 at 00:33

1 Answers1

1

So, this was a typical case of copy-paste... The problem was in this line:

Range(Match(Index("facturas_by_date")), Var("before"), Var("after"))

Note that the documentation for the Range function states this: Range( set, start, end ).

So, in my UDF code, the "before" variable corresponds with the start parameter. So when I say after January and before March, I am saying from March to January.

I fixed that and it works.

Danf
  • 1,409
  • 2
  • 21
  • 39