Code Monkey home page Code Monkey logo

Comments (3)

dan003400 avatar dan003400 commented on June 14, 2024 3
class ShopType < Types::BaseObject
    field :title, String, null: true

    field :user, Types::Models::UserType, null: true do
      guard ->(obj, args, ctx) { ctx[:current_user] && ctx[:current_shop] }
    end
  end

Just for anyone else who is looking to add guarded fields on BaseObjects.

from graphql-guard.

exAspArk avatar exAspArk commented on June 14, 2024 2

Thank you @dan003400. Right, the existing documentation was written by using the previous graphql gem schema-definition DSL.

For those who would like to contribute and update the readme to use class-based schema definitions, here is an example from the gem specs:

class PostType < GraphQL::Schema::Object
guard ->(_post, _args, ctx) { ctx[:current_user].admin? }
field :id, ID, null: false
field :title, String, null: true
end
class QueryType < GraphQL::Schema::Object
field :posts, [PostType], null: false do
argument :user_id, ID, required: true
guard ->(_obj, args, ctx) { args[:userId] == ctx[:current_user].id }
end
field :posts_with_mask, [PostType], null: false do
argument :user_id, ID, required: true
mask ->(ctx) { ctx[:current_user].admin? }
end
def posts(user_id:)
Post.where(user_id: user_id)
end
def posts_with_mask(user_id:)
Post.where(user_id: user_id)
end
end

from graphql-guard.

 avatar commented on June 14, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

from graphql-guard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.