I have a Keystone list schema that has a field of type 'File'.
So, a GraphQL mutation to update entity has an Upload GraphQL type for argument that corresponds to this field.
I need to execute update mutation using executeGraphql in server environment.
Did not found any plug-and-play solution for that.
One way, we are using for our test environment is to create an instance of ApolloClient and pass a link with createUploadLink from apollo-upload-client library. But, AFAIK, this approach will trigger real HTTP request.
It seems, like better way is to use existing instance of Keystone class on server sideā¦
Any recommendations?
Thank you.
Cheers!
Related
I am using Nest JS for server and new to Graphql, I want to create a graphql server but schema defines in Graphql module in app.module. I am using schema first appraoch.
app.module
in importing Graphql Module, typepaths property defines to create typings from schemas present in any path.
but I don't have any particular schema because I want my user to enter any thing he want and fetch data using Graphql where typings should be with respect to particular user.
Things I tried:
I tried to rewrite the schema using filesystem methods from service but to update typings from schema nest server needs to restart to generate typings again.
please anyone give me a guide or any approach how can I achieve dynamic typings. I want a server which shows a graphql playground but user should be allow to query with respect to their data.
like for user 1 this highlighted box can be a schema but for different user this schema should be with respect to himself:user 1 should see this schema and should query only using this schema
Related Images are attached in link.
Any guide would be appreciated, Thanks!
We marked some fields in our schema using the #deprecated directive. Now we want to log if these fields are still in use from some of our clients. What would be the best way to do this, without using Apollo Studio.
If you have access to the client code, then you can utilize GraphQL Inspector to check for deprecated usage. Using the CLI, you just do:
graphql-inspector validate DOCUMENTS SCHEMA
where DOCUMENTS is a glob pattern used to match the files containing the queries and SCHEMA is a pointer to the schema used for validation. The files containing the queries can be .graphql files or .js/.ts files. The schema pointer can be a URL to your schema or one or more .graphql files with your schema's type definitions. See here and here for additional ways to provide the schema and documents.
If you don't have access to the client code, or specifically need to log deprecated usage on every request, then you can write your own Apollo Server plugin and utilize GraphQL Inspector's programmatic API instead to validate each request's parsed document as it comes in. The parsed document will be available beginning with the validationDidStart lifecycle hook. See the docs for a complete example of how to write your own plugin.
I am a newbie in graphql and I am trying to create a sever which will take few parameters and a few files (like images) as parameters in mutation.
I am using graphql-yoga and it is very clear how to implement it using graphql-yoga.
My question is how to test it?
How can I test the file upload from graphql playground?
I am going to use react-relay so are there any examples to do it in react-relay.
Thanks.
Neither GraphiQL nor GraphQL Playground support file uploads. You can use a standalone client like Altair.
I started creating a laravel 5.8 based modular API framework for our company which should be extended using composer packages.
Now I stumbled over the problem to test each package by itself (each package has it's own GIT project of course) if the package needs to have access to the User model given in the base framework (App/Models/User).
There will be various packages naturally depending on the User model such as specific auth modules.
Unfortunately testing also gets more complex because we are using GraphQL (Lighthouse).
So how should this be done? I tried mocking App/Models/User with a User model contained in the tests folder of my package, but this did not work as expected:
$this->userMock = \Mockery::mock('CompanyName\\PackageName\\Tests\\User');
$this->app->instance('App\\Models\\User', $this->userMock);
When, after that, posting a GraphQL request the resolver method throws a Class App\Models\User does not exist error.
I am quiet new to testing with phpunit so maybe I am just missing something here?
Edit:
I just found out that the error message above is displayed because the User model is also referenced within the GraphQL schema file.
So I there is any solution out there it has to somehow "emulate" the not existing User model class for the whole request lifecycle I guess...
Ok I finally solved my problem which was more conceptual wise I guess. As the user model is pretty strongly tied to the (core) package I want to test, I have now moved the model into the package itself and removed it from the base project.
This has the advantage that the "end user developer" doesn't even see and has to cope with the user model which is handles by the package anyway.
Now I can test the package independently and only have to put a line of documentation into the README to tell, that a user has to change the auth.providers.users.modelvalue to let laravel use the appropriate model (e.g. CompanyName\\PackageName\\Models).
If there will be other packages extending the user model, they will have to depend on the core package (which they should either way) and can extend the model class and tell the user to update auth.providers.users.model again. This way it is also quiet transparent to see which user model is used currently.
For the GraphQL / Lighthouse part I have added the following code to the boot method of the package's service provider to make lighthouse know about new models within the package automatically:
$lighthouseModels = config('lighthouse.namespaces.models');
array_push($lighthouseModels, 'CompanyName\\PackageName\\Models');
config([
'lighthouse.namespaces.models' => $lighthouseModels
]);
This can be repeated for every package adding models as well so lighthouse knows about all of them.
Im trying to create a very basic Todo-entity from the Breeze example.. Im doing:
manager.createEntity("Todo",{Description:"Test",Id:32,IsDone:false});
But I keep getting an error where the console tells me that it couldnt find the Type "Todo".. I have tried all types I can possibly think of..
Could anyone please provide me with an example of how to create an entity for the breeze WebApiSample.. cause this is driving me nuts..
Thanks alot!
Breeze needs metadata in order to create an entity of any type. That metadata can either be returned from the server or created locally. My guess is that you haven't yet done either of these. Metadata from the server is usually automatically fetched by Breeze during its first query against the server. Alternatively you can cause it to be fetched directly via the MetadataStore.fetchMetadata method.
Hope this helps.