@@ -21,7 +21,7 @@ Create your adapter first
2121import  GraphQLAdapter  from  ' ember-graphql-adapter'  ;
2222
2323export  default  GraphQLAdapter .extend ({
24-   endpoint:  ` ${ EmberENV . apiBaseUrl } / graph` 
24+   endpoint:  ' http://localhost:3000/ graph' 
2525});
2626``` 
2727
@@ -73,11 +73,10 @@ module Graph
7373    name " Query" 
7474    description " The query root of this schema" 
7575
76-     field :post  do 
77-       type PostType 
76+     field :post , PostType  do 
7877      argument :id , ! types.ID , " The ID of the post" 
79-       resolve ->  (obj, args, ctw ) do 
80-         Post .find(args [:id ])
78+       resolve ->  (_object , arguments,  _context ) do 
79+         Post .find(arguments [:id ])
8180      end 
8281    end 
8382  end 
@@ -93,11 +92,10 @@ module Graph
9392    name " Mutation" 
9493    description " Mutations" 
9594
96-     field :postCreate  do 
97-       type PostType 
95+     field :postCreate , PostType  do 
9896      argument :name , ! types.String , " The post name" 
99-       resolve ->  (obj, args, ctw ) do 
100-         Post .create(name:  args [:name ])
97+       resolve ->  (_object , arguments,  _context ) do 
98+         Post .create(name:  arguments [:name ])
10199      end 
102100    end 
103101  end 
@@ -109,10 +107,10 @@ Now, we can build the whole schema
109107``` ruby 
110108#  app/models/graph/schema.rb
111109module  Graph 
112-   Schema  =  GraphQL ::Schema .new ( 
113-     query:   Graph ::QueryType , 
114-     mutation:   Graph ::MutationType 
115-   ) 
110+   Schema  =  GraphQL ::Schema .define  do 
111+     query Graph ::QueryType 
112+     mutation Graph ::MutationType 
113+   end 
116114end 
117115``` 
118116
@@ -121,7 +119,7 @@ In the controller we just delegate to the GraphQL schema
121119``` ruby 
122120#  app/controllers/graph_controller.rb
123121class  GraphController  < ApplicationController 
124-   def  index 
122+   def  execute 
125123    render json:  ::Graph ::Schema .execute(
126124      params.fetch(" query"  ),
127125      context:  {} #  you can pass the current_user here
@@ -134,7 +132,7 @@ Finally, we just expose the GraphQL endpoint in the route
134132
135133``` ruby 
136134#  config/routes.rb
137- get ' graph'  , to:  ' graph#index ' 
135+ get ' graph'  , to:  ' graph#execute ' 
138136``` 
139137
140138And that's it!
@@ -144,16 +142,16 @@ And that's it!
144142### Installation  
145143
146144*  ` git clone https://github.com/alphasights/ember-graphql-adapter.git ` 
147- *  ` npm install && bower  install` 
145+ *  ` yarn  install` 
148146
149147### Running  
150148
151- *  ` ember server ` 
149+ *  ` yarn start ` 
152150
153151### Running Tests  
154152
155- *  ` ember test --server ` 
153+ *  ` yarn run  ember test --  --server` 
156154
157155### Building  
158156
159- *  ` ember  build` 
157+ *  ` yarn  build` 
0 commit comments