Membership Role functionality

I have 2 functions that appear to be configured in exactly the same way. In Playground one works, the other does not:
CreateNewRanking - works
CreateNewUserJoinedRanking - does not
Both have collections configured as memberships in the same role (logged-in) and hence require tokens.
The same token header is therefore used by both functions in Playground.
Both have custom roles giving collection create and index read privileges. ie. they are both configured the same way.


AFAIK I have not made any extra configurations for one of these two functions and not the other.
How can one work and the other not, if they are both configured in the same way? thanks …

What do you mean by it not working? You need to provide more details. Both functions and the role (as FQL, not screenshots) should be a good starting point.

Thanks for your response. What I mean by it not working is that the function
CreateNewRanking - creates a new ranking document in the db, whereas the function
CreateNewUserJoinedRanking - does not create a new userjoinedranking document in the db.
CreateNewRanking FQL:

        {
  name: "create_new_ranking",
  role: Role("create_new_ranking"),
  body: Query(
    Lambda(
      ["active", "rankingname", "rankingdesc", "rankingowneraddr"],
      Let(
        {
          doc: Create(Collection("Ranking"), {
            data: {
              active: Var("active"),
              rankingname: Var("rankingname"),
              rankingdesc: Var("rankingdesc"),
              rankingowneraddr: Var("rankingowneraddr")
            }
          })
        },
        Var("doc")
      )
    )
  )
}

CreateNewUserJoinedRanking FQL:

    {
      name: "create_new_userjoinedranking",
      role: Role("create_new_userjoinedranking"),
      body: Query(
        Lambda(
          ["active", "rankingid", "rankingname", "rankingowneraddr"],
          Let(
            {
              doc: Create(Collection("UserJoinedRanking"), {
                data: {
                  active: Var("active"),
                  rankingid: Var("rankingid"),
                  rankingname: Var("rankingname"),
                  rankingowneraddr: Var("rankingowneraddr")
                }
              })
            },
            Var("doc")
          )
        )
      )
    }

Logged-in role:

{
  ref: Role("logged-in"),
  ts: 1598603402100000,
  name: "logged-in",
  privileges: [
    {
      resource: Ref(Ref("functions"), "all_user_names"),
      actions: {
        call: true
      }
    },
    {
      resource: Ref(Ref("functions"), "create_new_ranking"),
      actions: {
        call: true
      }
    },
    {
      resource: Ref(Ref("functions"), "create_new_player"),
      actions: {
        call: true
      }
    },
    {
      resource: Ref(Ref("functions"), "create_new_userjoinedranking"),
      actions: {
        call: true
      }
    }
  ],
  membership: [
    {
      resource: Collection("User")
    },
    {
      resource: Collection("Ranking")
    },
    {
      resource: Collection("Player")
    },
    {
      resource: Collection("UserJoinedRanking")
    }
  ]
}

CreateNewRanking role:

{
  ref: Role("create_new_ranking"),
  ts: 1598495839686000,
  name: "create_new_ranking",
  privileges: [
    {
      resource: Collection("Ranking"),
      actions: {
        read: false,
        write: false,
        create: true,
        delete: false,
        history_read: false,
        history_write: false,
        unrestricted_read: false
      }
    },
    {
      resource: Index("allRankings"),
      actions: {
        unrestricted_read: false,
        read: true
      }
    }
  ],
  membership: []
}

CreateNewUserJoinedRanking role:

{
  ref: Role("create_new_userjoinedranking"),
  ts: 1598597054483000,
  name: "create_new_userjoinedranking",
  privileges: [
    {
      resource: Collection("UserJoinedRanking"),
      actions: {
        read: false,
        write: false,
        create: true,
        delete: false,
        history_read: false,
        history_write: false,
        unrestricted_read: false
      }
    },
    {
      resource: Index("allUserJoinedRanking"),
      actions: {
        unrestricted_read: false,
        read: true
      }
    }
  ],
  membership: []
}

Hope the FQL makes the configuration clearer ... thanks again ...

So this results in a permission denied error?

I tried 2 definitions for CreateNewUserJoinedRanking:

mutation CreateNewUserJoinedRanking {
  createNewUserJoinedRanking(
    data: {
      active: true
      rankingid: "274890605431095813"
      rankingname: "Test 1"
      rankingowneraddr: "0x267be913fc79bbecb3c3ec88332a537d1c593a6d"
    }
  ) {
    active
    rankingid
    rankingname
    rankingowneraddr
  }
}

results in:

{
  "data": null,
  "errors": [
    {
      "message": "Unknown argument 'data' on field 'createNewUserJoinedRanking' of type 'Mutation'. (line 2, column 30):\n  createNewUserJoinedRanking(data: {active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\"}) {\n                             ^",
      "locations": [
        {
          "line": 2,
          "column": 30
        }
      ]
    },
    {
      "message": "Field 'createNewUserJoinedRanking' argument 'active' of type 'Boolean!' is required but not provided. (line 2, column 3):\n  createNewUserJoinedRanking(data: {active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\"}) {\n  ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    },
    {
      "message": "Field 'createNewUserJoinedRanking' argument 'rankingid' of type 'String!' is required but not provided. (line 2, column 3):\n  createNewUserJoinedRanking(data: {active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\"}) {\n  ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    },
    {
      "message": "Field 'createNewUserJoinedRanking' argument 'rankingname' of type 'String!' is required but not provided. (line 2, column 3):\n  createNewUserJoinedRanking(data: {active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\"}) {\n  ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    },
    {
      "message": "Field 'createNewUserJoinedRanking' argument 'rankingowneraddr' of type 'String!' is required but not provided. (line 2, column 3):\n  createNewUserJoinedRanking(data: {active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\"}) {\n  ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

The second definition:

mutation CreateNewUserJoinedRanking {
  createNewUserJoinedRanking(
      active: true
      rankingid: "274890605431095813"
      rankingname: "Test 1"
      rankingowneraddr: "0x267be913fc79bbecb3c3ec88332a537d1c593a6d"
  )
}

results in:

{
  "data": null,
  "errors": [
    {
      "message": "Field 'createNewUserJoinedRanking' of type 'UserJoinedRanking!' must have a sub selection. (line 2, column 3):\n  createNewUserJoinedRanking(active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\")\n  ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

So, at this point, not a permissions denied error. I am currently not configuring/defining the FQL correctly …

This results in:

{
  "data": null,
  "errors": [
    {
      "message": "Field 'createNewUserJoinedRanking' of type 'UserJoinedRanking!' must have a sub selection. (line 2, column 3):\n  createNewUserJoinedRanking(active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\")\n  ^",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

So this is a GraphQL error, I’m not too familiar with Faunas GraphQL implementation, but this seems to be an issue with the graphQL query. Im guessing you have a {} without specifying any sub fields. Please provide the corresponding query if you don’t figure it out. And for future posts always include the error message.

@FreeRoss can you please share the GraphQL schema for the queries CreateNewRanking and CreateNewUserJoinedRanking, preferably entire schema file along with the query which results in below error.

This error tells that the GraphQL side of data does not match with the data returned on fql side.

      "message": "Field 'createNewUserJoinedRanking' of type 'UserJoinedRanking!' must have a sub selection. (line 2, column 3):\n  createNewUserJoinedRanking(active: true, rankingid: \"274890605431095813\", rankingname: \"Test 1\", rankingowneraddr: \"0x267be913fc79bbecb3c3ec88332a537d1c593a6d\")\n  ^",
1 Like

@eigilsagafos thanks for your response. I hadn’t included _id in the response fields (and extra {} which I removed). It works now. I will include error messages in future posts …

@Jay thanks for your response. I hadn’t included _id in the response fields (and extra {} which I removed). Also you correctly alerted me to an incompatible field definition in the schema. It works now.

1 Like