Comments (9)
What do you mean? Just return whatever you want in the Query/Mutation resolve()
function. It can come from Eloquent or DB or it doesn't even have to interact with the database.
from graphql-laravel.
You're saying to do something like this?
class ClickQuery extends Query {
...
public function resolve($root, $args)
{
return DB::table('click')
->select(DB::raw('user_id, count(distinct click.id) as click_count'))
->join('user', 'user.id', '=', 'click.user_id')
->groupBy('user_id')
->get();
}
If I do that, how do I relate it to other querys? Please look at this query.
{
"query": "{user{id, email, first_name, clicks{click_count}}}"
}
How can it connect it to the UserQuery in this? There is no relation since it is outside of Eloquent.
from graphql-laravel.
I guess what I am asking is how do I setup relations in the Type file if I am not using Eloquent?
from graphql-laravel.
If you're not using Eloquent, then just omit the model
property from the Type's $attributes
. But this way you obviously cannot create relations to other tables
from graphql-laravel.
So there is no way to create the parent/child query in the POST without using Eloquent?
Example below. Is it possible to return something like this without Eloquent?
{
"query": "{ users {id, email, first_name, profile {id, twitter_url, facebook_url, modified} } }"
}
from graphql-laravel.
It's possible, by just returning an array in the resolve
method, for example:
return [
'id' => 1,
'email' => '[email protected]',
'profile' => [
'id' => 1,
...
],
...
];
But you also have to set 'selectable' => false
for each field
from graphql-laravel.
Thanks. So just to confirm, if we were going to query the DB (without Eloquent) we would need to build that multi-dimensional array? Something like this (pseudo-ish code)?
$db_rows = DB::table('user')
->select(DB::raw('id, twitter_url'))
->join('profile', 'profile.id', '=', 'user.profile_id')
->get();
$db_rows = $db_rows->toArray();
$response = array();
$n = 0;
foreach ($db_rows as $row) {
$response[$n]['id'] = $row['id']; // Parent element
$response[$n]['profile']['twitter_url'] = $row['twitter_id']; // Child element
$n++;
}
return $response;
I just want to confirm that this would be the best practice in this kind of scenario.
from graphql-laravel.
Yes, this would work (no need for even $db_rows->toArray()
as you can iterate over a Collection with foreach)
from graphql-laravel.
Awesome - thanks so much for your help.
from graphql-laravel.
Related Issues (20)
- Tests are failing on CI HOT 3
- Cannot upgrade to laravel 10x because it cannot coexist with rebing dependency illuminate/contracts and illuminate/support
- Playground, are you thinking of implementing it?
- Unable to enable apq caching
- Is there documentation on returning objects with relation objects as a part of the type? HOT 4
- Pagination on Relation HOT 1
- Unexpected end of JSON input HOT 3
- queryContext in GraphQLController doesn't exist HOT 2
- L11: Unresolvable dependency resolving [Parameter #4 [ <required>; string $basePath ]] in class Illuminate\Foundation\Exceptions\Renderer\Renderer (500 Internal Server Error) HOT 1
- Improve error reporting when a type's name has illegal characters HOT 2
- GraphQL Request must include at least one of those two parameters: \"query\" or \"queryId\" HOT 3
- Add support for thecodingmachine/safe 2.0 HOT 2
- Nullable and Filled
- Resolver context is not updated once a user is logged in HOT 2
- repo description nit
- Pagination error HOT 2
- Integration tests for L9 are not working anymore
- useing $args in the resolve cloture of a type item
- Missing parent table in SelectFields for UnionType and InterfaceType HOT 3
- Using getRelations of SelectFields involves only selecting the requested fields for relationships HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-laravel.