Skip to content

vivekmiyani/phantom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phantom

Graphql

Shorthand

  • Includes enum shorthand,

    field :status, enum("PersonStatusEnum", Person.statuses.keys), null: false

Response handler

  • Catches errors automatically:

    • ActiveRecord::RecordNotFound
  • Includes raise_error response handler in GraphQL::Schema::RelayClassicMutation

    raise_error person.errors.full_messages.to_sentence unless person.update(status: :active)

Authorization

  • Add authorize option to field

    # app/graphql/types/base_field.rb
    
    field_class.include(Phantom::Graphql::FieldExtensions)
    field :posts, [Types::PostType], authorize: "PostPolicy#index?", null: false

Preload to prevent N+1

  • Pass asscoation name in preload which will fix N+1 query

  • Pass Policy name in scope, which will reduces scope in preloaded query

    class Types::PostType < Types::BaseObject
      field :comments, [Types::CommentType], scope: "CommentPolicy", preload: :comments, null: false
    end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Languages