Graphql schema for add friends - graphql

Hi I want to create schema for friends functionality. Where logged in user can send friend request to registered users. I have 2 table users and relation and can be able to get own friends. Its working in redux and react with node mysql. But I don’t know how i can achieve the same in GraphQL. I am using GraphQL prisma now using GraphQL cli

I suggest you learn about GraphQL here: https://graphql.org/learn/ and then about Prisma here: https://www.prisma.io/docs/
This will help you understand how to create a GraphQL Schema for your needs and how to use Prisma to abstract the database access

Related

AWS Amplify Graphql Creating a new User table, necessary?

I'm fairly new to Amplify and been playing around with it for a couple of weeks now. I've been incorporating it into Next.js, which is pretty nice.
I originally created a new User table/record using lambda function: after a user signs up and confirms their email, it should automatically create a new record in the User table with some information. I only did this because I thought Amplify only provided a few attributes, but until recently I found out that you can pretty much create custom attributes.
So, because of this, would there be an argument to create another User table? I would like to know how people are handling User information in big applications.
I guess one thing I can think of is making relationships with other tables. I haven't gone too far into figuring this out, but is it possible to still make connections if I don't have User table in my graphql schema?
Yes I have the same issue and was thinking to have a Users table where I enable owner authorization. This Owner-based authorization allows you to tie a data record to a user. Owners can read, create, update, and delete the record.
Allow the owner to perform these operations on their own records:
Create
Read
Update
Delete

Graphql query works in installed app but not in GraphiQL

very new to shopify and graphql
i created a sample shopify shop and installed shopify graphQL app in it.
when i run this query in the installed app i get results
when i run the same query from the C# code or GraphiQL
i get this error
"Field 'inventoryItems' doesn't exist on type 'QueryRoot'"
i have headers set like this.
The GraphiQL app uses the Admin GraphQL and you are trying the StoreFront GraphQL.
The Admin and StoreFront GraphQL are very different from one another. The admin GraphQL is used for creating/updating/deleting/outputing items from your store, but the StoreFront GraphQL is mainly used for outputting data since it's public and it will be huge security issue if could modify your store.
Because of that both APIs have different access to different methods and there are methods that are available only for the Admin GraphQL and the other way around, there are methods only available to the StoreFront GraphQL as well.
TL;DR inventoryItems method is not available for the Storefront GraphQL, you can access it from the Admin GraphQL.

User table with users following other users in Amplify

I'm new to GraphQL and Amplify, and I basically want to accomplish this from the cli:
type User #model {
id: ID!
follows: [User]
}
So a user can follow other users, and I want to be able to add users to follow to a user, get a list of the users a user follows, and also list all the users who follows a specific user. I would guess this quite basic setup shuold be possible quite easily from the cli as I have been able to setup other such relations (but between different types), however, this (maybe naive) schema does not give me the mutations and queries I would like when running amplify push api.
What is the best way to accomplish what I want?

How to use permissions with Laravel API and Calling Application

I have setup an API in Laravel using Passport for authentication and spatie/laravel-permission to add permission functionality. I also have a calling application, again written in Laravel. I can authenticate from the calling app to the api but how do i ensure that the calling app knows the permissions available? What should the user/roles/permissions tables look like at the api and in the calling app?
Essentially i would like to use code like: $user->can('do something') in both applications.
My understanding of the Spatie package is that it allows you to make such code calls as $user->can('do something'), and reading the Github page it looks like it creates tables default named "role" and "permission" when you run the Migration after installing the package. In other words it's a matter of configuring the models and database connections in both of your apps correctly, specifically the User Model and the Permission table for both apps.
To clarify, I think you are asking these questions:
how can a second app know what permissions are available,
how would you be able to use something like "$user->can('do something')" in BOTH applications, touching the exact same data.
Answers:
If the "permission" and "role" tables already exist, then if your API doesn't have some endpoint to ask for the roles or permissions already available, you'd define a new one. For instance, some API call that asks the Permission table "getPermissions" or something and that your second application can call -- it either has to ask the database itself (via the API), or it has to get that from the second application. Which depends on how your two applications interact with each other
you would have to make sure to configure the second application so that the "User" model refers to the same table as the table the first application uses for the User model. Essentially, the model is being used as an interface to the table, so if both applications have a defined User model that references the same table and both are configured to connect to the same database that table is in, Laravel's user model will "just know" the data in question (this is the basis of Laravel's Eloquent for Models).
Additionally, for what it's worth, I haven't used the spatie/laravel-permission package, but in relation to question #1 I did find a function in the docs that might also be used to grab currently made permissions in list form from a "permission table":
Permission Model, getPermissions
And for reference, about Laravel's Eloquent and Models (which may be something you already know, but I'll leave this link anyway):
Laravel Eloquent ORM

Odata & Entity Framework, Many to Many relationship won't update

I'm writing an OData / Entity Framework client server app, and can't get Many to Many relationships to update from the client to the server.
The OData server is written using VS2013 in c# using WCF 5.6, and Entity Framework 6.
The database is simply 3 tables, Users, Permissions and a joining table UsersPermissions.
I'm using Entity Framework 6, which abstracts away the joining UsersPermissions table, leaving just the Users and Permissions entities.
From a User I can query their permissions no problem from a client using LINQ. Similarly I can query Users from Permissions, so the many to many relationship is good for reading from.
If I try to create a relationship from the client, say adding a new permission for a user, nothing happens. No traffic to the server, no data is changed in the joining table in the database.
This is the same whether I try to add a permission to a user in my client application, or if I use LinqPad to execute the query against my OData source.
The LINQ I'm using (taken from LinqPad) is:
// Get permission
var Permission = (from p in Permissions
where p.PermissionId == 1
select p).SingleOrDefault();
// Get user
var User = (from u in Users
where u.UserId == 1
select u).SingleOrDefault();
// Add permission to user
User.Permissions.Add(Permission);
SaveChanges();
I have tried creating a completely separate OData server application, and get the same problem.
If I execute the above LINQ within the OData server app, it executes as expected and the entry is added to UsersPermissions.
So it seems that the problem only exists when trying to update a many to many relationship from an OData client?
There is mention at the end of this article that OData has a bug in refreshing many to many relationships, but I can't even create one! http://msdn.microsoft.com/en-us/library/vstudio/bb896317(v=vs.100).aspx
I'd appreciate any help or suggestions towards tracking down why I cant create a many to many relationship from an OData client against an OData server using EF6.0.
To add a relationship between user and permission on client side, Please use DataServiceContext.AddLink
dsc.AddLink(User, "Permissions", Permission)
dsc.SaveChanges()

Resources