Graphql custom fuzzy search dql query dosn't work

I’m trying to create a GraphQL query that makes a fuzzy search, but it just returns an empty array. I have tried many different ways, but the documentation isn’t helping. I don’t get it, aren’t you supposed to do it like this or why is it so hard?

Here is my GraphQL query:

type Query {
			querySearchRooms(SEARCH: String!): [Room] @custom(dql: """
					query q ($SEARCH: string) {
							querySearchRooms (func: match(name, $SEARCH, 3)) {
    						id
  						}
					}""")
}

The “Room”-type looks like this:

type Room {
  id: ID!
  name: String! @id @search(by: [trigram])
}

Change id to Room.id, name to Room.name in your dql.

I updated it and it still returns an empty array.

type Query {
  searchRoom(search: String!): [Room]
    @custom(
      dql: """
        query q ($search: string){
          searchRoom(func: match(Room.name, $search, 3)) {
      				Room.id
          }
        }"""
    )
}

Change id to uid.

Nope, still the empty array.

type Query {
  searchRoom(search: String!): [Room]
    @custom(
      dql: """
        query q ($search: string){
          searchRoom(func: match(Room.name, $search, 3)) {
      				Room.uid
          }
        }"""
    )
}

I see, you should use alias.

type Query {
  searchRoom(search: String!): [Room]
    @custom(
      dql: """
        query q ($search: string){
          searchRoom(func: match(Room.name, $search, 3)) {
      				id:uid
                    name:Room.name
          }
        }"""
    )
}
2 Likes