New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use custom link, cache and cache options #96
Use custom link, cache and cache options #96
Conversation
Allows the usage of: - Custom link - Custom cache - Custom cache options Fixes awslabs#3 Fixes awslabs#21 Fixes awslabs#24 Fixes awslabs#36 Fixes awslabs#52 Fixes awslabs#70 Fixes awslabs#87 Closes awslabs#62
@manueliglesias Can you give an example of how to add a custom cache using your PR? |
Also, I tried to use the code from this pull request and received a error related to line 103 of client.js stating that super can't be used prior to this. |
Hi @reggie3 This is how you would use a custom cache, please note that offline support needs to be disabled (the custom cache won't know how to write to the offline store): import { Hermes } from 'apollo-cache-hermes';
import AWSAppSyncClient from "aws-appsync";
const cache = new Hermes({ verbose: true });
const client = new AWSAppSyncClient({
url: appSyncConfig.graphqlEndpoint,
region: appSyncConfig.region,
auth: {
type: appSyncConfig.authenticationType,
apiKey: appSyncConfig.apiKey
},
disableOffline: true
}, { cache }); |
@reggie3 I also added a couple commits to address eslint rules (Hopefully that takes care of the webpack errors, let me know if it works for you) Thanks for trying this SDK! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, but lets talk tomorrow. Probably I didn't understand some stuff
@@ -217,7 +217,7 @@ var sign = function (request, access_info, service_info = null) { | |||
|
|||
// datetime string and date string | |||
var dt = new Date(), | |||
dt_str = dt.toISOString().replace(/[:\-]|\.\d{3}/g, ''), | |||
dt_str = dt.toISOString().replace(/[:-]|\.\d{3}/g, ''), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is dt_str
defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is part of the same var
statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol thanks!
let theLink; | ||
|
||
return new ApolloLink((op, forward) => { | ||
if (!theLink) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you checking this theLink
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I want to create the link only once and re-use it on subsequent link invocations. For this I am creating a closure
} = {}, options = {}) { | ||
const { cache: customCache, link: customLink } = options; | ||
|
||
if (!customLink && (!url || !region || !auth)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add on the error message or customLink
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
}); | ||
let resolveClient; | ||
|
||
const store = disableOffline ? null : createStore(() => this, () => resolveClient(this), conflictResolver); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to talk tomorrow the use of resolveClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manueliglesias I don't have reproducible steps yet, but I can sometimes trigger an error in my app around this new area of the appsync sdk code:
TypeError: resolveClient is not a function. (In 'resolveClient(_this)', 'resolveClient' is undefined)")
It seems to be thrown when I invoke a lambda outside the context of appsync, while the app is starting up. Sorry I don't have more actionable information yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When disableOffline=false, I applied this workaround to prevent the "resolveClient is not a function" error: apollographql/apollo-link#493 (comment)
let resolveClient; | ||
|
||
const store = disableOffline ? null : createStore(() => this, () => resolveClient(this), conflictResolver); | ||
const cache = disableOffline ? (customCache || new InMemoryCache(cacheOptions)) : new OfflineCache(store, cacheOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happen if someone use customCache
with cacheOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, cacheOptions
would be ignored. It is inferred that your customCache
is already initialized with whatever options you chose.
handle = passthrough(op, forward).subscribe(observer); | ||
}).catch(observer.error); | ||
|
||
return () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this return will run before waiting hydratedPromise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, an Observable
"Returns a cleanup function which will cancel the event stream". For reference, see: https://github.com/tc39/proposal-observable#example-observing-keyboard-events
@manueliglesias Thank you for working on it. I'm really excited about incorporating your work into my project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice!
@manueliglesias Would the correct combination of custom cache and link-state be a combination of your example above and the one from #24? Would it be something like this?
This is what I'm trying to us now, but it isn't working yet. I'm trying to figure out if I'm on the right track. EDIT: Just want to add, that auth includes a variable for type which most tutorials pull from your AppSync configuration file as "authType". The relevant key is actually called "authenticationType"in the JSON file that AppSync will export for you when building your GraphQL schema. |
Use custom link, cache and cache options
Issue #, if available:
Fixes #3
Closes #21
Fixes #24
Closes #25
Fixes #36
Fixes #52
Closes #62
Fixes #70
Fixes #87
Fixes #90
Closes #92
Description of changes:
Allows the usage of:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.