marvinrabe / laravel-graphql-test Goto Github PK
View Code? Open in Web Editor NEW🛠 Elegant GraphQL testing utilities for Laravel.
License: MIT License
🛠 Elegant GraphQL testing utilities for Laravel.
License: MIT License
I have tried testing the authentication process with PHPUnit. I have managed to test all mutations apart from the logout.
$this->mutation('logout', ['status', 'message']); logout = the mutation, [status and message] = the LogoutResponse payload
When I run that, I get the below error message:
“message” => “Syntax Error: Expected Name, found Int”
It would seem that it is asking for a second parameter (Which I am guessing is the Authorization Bearer info), but in the schema, there are no parameters, just the payload:
Schema: logout: LogoutResponse!
I have got it working with another package:
$response = $this->postGraphQL([
'query' => 'mutation {
logout {
status
message
}
}'
], [
'Authorization' => 'Bearer '.$token
]);
But I would ideally like to get it working with your package.
Would appreciate a stir in the right direct.
Make it easy to pass UploadedFile objects as attributes to a mutation.
Hello,
Thak thank you support this project.
I just upgraded one of my projects and got an error in phpDoc.
Your package describes \Illuminate\Foundation\Testing\TestResponse as a returning type.
But In laravel 8 it has been moved to \Illuminate\Testing\TestResponse.
Example: file marvinrabe/laravel-graphql-test/src/TestGraphQL.php
/**
* Returns a TestGraphQL client. If no arguments and selection is provided, it will query the server directly.
* @param string $object GraphQL query name
* @param array|null $arguments Specifies arguments send to the server. When selection is null it will be used as a selection set instead.
* @param array|null $selection Specifies Selection set send to the server.
* @return GraphQLClient|\Illuminate\Foundation\Testing\TestResponse
**/
public function query(string $object, $arguments = null, $selection = null)
{
$client = GraphQLClient::query($object, function ($query) {
return $this->postJson(
$this->graphQLEndpoint ?? 'graphql',
[
'query' => $query,
]
);
});
return $this->prepareClient($client, $arguments, $selection);
}
My tests still working but ide inform that It can't find a response and autocomplete doesn't work anymore.
I can create PR just let me know
Nice work @marvinrabe
This library make our life easier for our GraphQL testing.
Recently I encounter the same issue as #3 when I tried to test logout mutation that doesn't need any arguments and selection
I tried your suggestion in #3:
$this->mutation('logout', [], ['status', 'message'])
and
$this->mutation('logout', [])
and found that it always returns GraphQLClient because in php empty array is equals to null
I've submitted a PR fix for this, please take a look
#4
i want to set authentication header for my test.
how can i do this ?
in postJson
i can set header parameter. should i edit package manually ? or we have any option to add header in requests.
and also thank you for this package
Currently:
$this->setArguments(['enum' => 'foo'])
results in
(enum: "foo")
Expected:
$this->setArguments(['enum' => 'foo'])
results in
(enum: foo)
Workaround:
Create a class
class Enum {
protected $value;
public function __construct($value) {
$this->value = $value;
}
public function __toString() {
return $this->value;
}
}
And then:
$this->setArguments(['enum' => new Enum('foo')])
results in
(enum: foo)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.