A problem with search directive


I have these types in my schema:

type Repository {
  id: ID!
  name: String! @search(by: [regexp, term, exact])
  members: [Membership!] @search
type Membership {
  id: ID!
  belongsTo: User! @hasInverse(field: memberships)
  in: Repository! @hasInverse(field: members)

(*I removed some fields to keep it clean)
When I try to deploy this scheme to slash, I get the following error:

"resolving updateGQLSchema failed because input:84: Type Repository; Field members: has the @search directive but fields of type Membership can't have the @search directive"

Why does it happen and how can I fix it?


Hi @spinelsun
@search can be applied on the following types

  • Int, Float
  • DateTime
  • Boolean
  • String
  • Enums

While @search cannot be directly applied to a type, the documentation has an example of deep querying that could be useful for your use case.

type Post {
    title: String @search(by: [term])

type Author {
    name: String @search(by: [hash])
    posts: [Post]


queryAuthor(filter: { name: { eq: "Diggy" } } ) {
    posts(filter: { title: { anyofterms: "GraphQL" }}) {

So this query should bring al the branches of repositories that the user has membership in them

query($USER: String!){
        belongsTo(filter: {username: {eq: $USER}}){username}

If I put it on auth rule for add it will block users from adding new branches to repos that they are not belong to right?

Please review a similar example is mentioned in the documentation here. I think the use case you mentioned should work.
Here is the example query:

query ($USER: String!) { 
    queryTodo {
        owner(filter: { username: { eq: $USER } } ) { 
1 Like