Giter VIP home page Giter VIP logo

Comments (3)

spawnia avatar spawnia commented on July 23, 2024

There is a test for this, perhaps you can add a failing test case for your scenario?

public function testInjectArgsPassesClientArgumentToPolicy(): void
{
$this->be(new User());
$this->mockResolver(fn (): User => $this->resolveUser());
$this->schema = /** @lang GraphQL */ '
type Query {
user(foo: String): User!
@can(ability: "injectArgs", injectArgs: true)
@mock
}
type User {
name: String
}
';
$this->graphQL(/** @lang GraphQL */ '
{
user(foo: "bar") {
name
}
}
')->assertJson([
'data' => [
'user' => [
'name' => 'foo',
],
],
]);
}

from lighthouse.

SlyDave avatar SlyDave commented on July 23, 2024

Thanks for the quick response, that test doesn't cover the case, as it doesn't use variables to pass in the arguments.

Once I am back in the office on Monday I'll attempt to put together something.

But generally speaking, it looks something like the following, for a query using Type rather than a mutation using Input:

     public function testInjectArgsPassesClientArgumentToPolicy(): void 
     { 
         $this->be(new User()); 
  
         $this->mockResolver(fn (): User => $this->resolveUser()); 
  
         $this->schema = /** @lang GraphQL */ ' 
         type Query { 
             user(foo: String): User! 
                 @can(ability: "injectArgs", injectArgs: true) 
                 @mock 
         } 
  
         type User { 
             name: String 
         } 

         type Foo { # Here we define the type to use as a variable.
             foo: String
         }
         '; 
  
         $this->graphQL(/** @lang GraphQL */ ' 
        query getUser($foo: Foo) {  # Here we set the query operation and tell it use to our Foo type as a variable.
             user(foo: $foo) { 
                 name 
             } 
         } 
         ', ['foo' => 'bar'] # Here we pass the variables into the graphQL helper
        )->assertJson([ 
             'data' => [ 
                 'user' => [ 
                     'name' => 'foo', 
                 ], 
             ], 
         ]); 
     } 

from lighthouse.

SlyDave avatar SlyDave commented on July 23, 2024

The actual test is:

    public function testInjectArgsPassesClientVariablesToPolicy(): void
    {
        $this->be(new User());

        $this->mockResolver(fn (): User => $this->resolveUser());

        $this->schema = /** @lang GraphQL */ '
         type Query {
             user(foo: String): User!
                 @can(ability: "injectArgs", injectArgs: true)
                 @mock
         }

         type User {
             name: String
         }
         ';

        $this->graphQL(/** @lang GraphQL */ '
        query getUser($foo: String) { 
             user(foo: $foo) {
                 name
             }
         }
         ', ['foo' => 'bar']
        )->assertJson([
            'data' => [
                'user' => [
                    'name' => 'foo',
                ],
            ],
        ]);
    }

and what would you know, it passes.

OK (1 test, 2 assertions)

Because I am an idiot. and I am using @spread on the Input so the outer associate key doesn't exist.

Sorry for wasting your time.

from lighthouse.

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.