apollo-link-rest | Use existing REST endpoints with GraphQL | GraphQL library
kandi X-RAY | apollo-link-rest Summary
kandi X-RAY | apollo-link-rest Summary
Use existing REST endpoints with GraphQL
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of apollo-link-rest
apollo-link-rest Key Features
apollo-link-rest Examples and Code Snippets
const httpLink = createHttpLink({ uri: "server.com/graphql" });
const restLink = new RestLink({ uri: "api.server.com" });
const client = new ApolloClient({
link: ApolloLink.from([authLink, restLink, errorLink, retryLink, httpLink]),
// Note: htt
mutation deletePost($id: ID!) {
deletePostResponse(id: $id)
@rest(type: "Post", path: "/posts/{args.id}", method: "DELETE") {
NoResponse
}
}
Community Discussions
Trending Discussions on apollo-link-rest
QUESTION
I'm using Apollo to call a rest endpoint that takes variables from query string:
/api/GetUserContainers?showActive=true&showSold=true
I'm having trouble figuring out how to pass variables to the query, so it can then call the correct url. From looking at apollo-link-rest docs and a few issues I think I'm supposed to use pathBuilder
but this is not documented and I haven't been able to get it working.
So far I've defined my query like this:
...ANSWER
Answered 2020-Nov-14 at 09:22You shouldn't need to use the pathBuilder
for simple query string params. You can pass your params directly as variables to useQuery
then pass then directly into teh path
using the {args.somearg}
syntax. The issue I see is you've not defined the variables your using for you query containerHistory
bu only in the query alias RESTgetUserQueries
. If updated is should look like this:
QUESTION
I'm trying to update from "apollo-server": "^2.9.4" and "apollo-server-express": "^2.9.4" to 2.12.0 version in Typescript, During the build process of the app I get the following error:
node_modules/apollo-server-express/node_modules/apollo-server-core/dist/plugin/index.d.ts:1:13
error TS1005: '=' expected.
1 import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
I have not found the fix for this yet, I've deleted node_modules folder and package-lock.json but still not working.
It would be nice to have some help....
...ANSWER
Answered 2020-Oct-28 at 11:53The import type
syntax used in apollo-server-core isn't supported by the version of typescript that you're using (v3.6). This syntax became available from v3.8 onwards. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
Update typescript and the error will disappear
QUESTION
I started using ApolloClient and i must say, the documentation is horrible.
My application will use GraphQL, but the login needs to be done using a simple POST
request to /login
providing the username and password, as formdata.
And man, getting that to work has been a complete nightmare.
Since i have to use apollo-link-rest
i have to first build my client:
ANSWER
Answered 2020-Jul-12 at 13:27According to Response transforming, apollo expects response from REST APIs like the following:
QUESTION
It works perfectly, with a single endpoint. With apollo-link-rest, I have made a client that looks like this
...ANSWER
Answered 2020-Mar-23 at 11:39You can (should be possible) use standard method to make similar queries - get many data (result) nurmally available as the same shape (node name). This is described here.
QUESTION
I am creating an app using React and the Apollo Graphql client. This app must have a local resolver to retrieve data from a legacy REST API and write it to the cache.
What I expect from this resolver is that it will first try to get the data from the local cache and then if it is not there, it will fetch it from the legacy API. However sometimes this data is also updated by other parts of my application, so in this case I would like the resolver to ignore the cache and go directly to the legacy API.
I know that what I described above is similar to the fetchPolicies
that the Apollo Client provides: the first scenario would be cache-first
and the second would be network-only
and I would like to use them to determine my resolver's behavior.
However I wasn't able to find the fetchPolicy
in my resolver's arguments. The resolver's function signature that I am using now is this:
ANSWER
Answered 2019-Nov-11 at 12:45I just saw this part of the Apollo client documentation that I think I missed before: https://www.apollographql.com/docs/react/data/local-state/#working-with-fetch-policies.
Basically it says that the fetch-policies
are evaluated before the resolver is called and that they work just like when calling a remote resolver.
So, I ran some tests and by using the default policy (cache-first
), my resolver is called only once and the rest of the times the result is returned directly from the cache.
If I change the fetch-policy
to network-only
than my resolver function is always called.
QUESTION
Trying to get the nested data downloads.copy
to render on page. I see the data with Apollo Client Dev Tools but won't render to page. I've searched through the apollo-link-rest issues. I'm sure this is some syntax problem - or not. Any help/insight will be much appreciated.
ANSWER
Answered 2019-Apr-25 at 00:11downloads
is an array - use tool.downloads[0].copy
Query should contain an id
field in downloads
- to properly cache ToolsPayloadDownloads
type.
You can check this/inspect apollo cache data/details using react dev tools.
QUESTION
I am trying to use apollo-link-rest
with the Star Wars API and I am getting some errors.
ANSWER
Answered 2018-Nov-15 at 19:31Check out what the docs have to say about typename patching.
Your @rest
directive tells the client what typename to expect for the search
field, but doesn't say anything about any types inside the field's selection set. There's two ways to fix that. You can use a @type
directive:
QUESTION
EDIT: The problem described below is a problem of the api i used... not a problem with apollo.
I am trying to use apollo-link-rest
with a api-key set in the header.
If I try to use the exact same api endpoint and set the api-key as header in Postman app, it works perfectly fine.
But not for apollo-link-rest
:
ANSWER
Answered 2018-Oct-13 at 15:48Can you try this? I kind of based my answer on this: https://www.apollographql.com/docs/link/links/rest.html#context
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install apollo-link-rest
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page