-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set link user to current_user on creation
- Loading branch information
Showing
6 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
class Resolvers::CreateLink < GraphQL::Function | ||
# arguments passed as "args" | ||
# Arguments passed as "args" | ||
argument :description, !types.String | ||
argument :url, !types.String | ||
|
||
# return type from the mutation | ||
# Return type from the mutation | ||
type Types::LinkType | ||
|
||
# the mutation method | ||
# The mutation method | ||
# _obj - is the parent object, which in this case is nil | ||
# args - are the arguments passed | ||
# _ctx - is the GraphQL context | ||
def call(_obj, args, _ctx) | ||
# ctx - is the GraphQL context | ||
def call(_obj, args, ctx) | ||
Link.create!( | ||
description: args[:description], | ||
url: args[:url], | ||
user: ctx[:current_user] | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class Link < ApplicationRecord | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddUserIdLink < ActiveRecord::Migration[5.1] | ||
def change | ||
change_table :links do |t| | ||
t.references :user, foreign_key: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters