-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Support for client side resolvers (apollo-link-state) #197
Comments
I haven't found it useful as Although, some of the frameworkish tools like middlewares or guards might help in creating resolvers for managing state, so it might help in an other way. But no, for now it won't work as TypeGraphQL build the executable schema using |
Actually it does have typdefs for apollo client devtools. And it can still help with generating the resolvers from a set of classes. |
I haven't found any info about it even in issues. The official docs says that there's no type checking: |
I was just looking into this same issue today, so I am totally +1 on this. Whoever writes his backend with type-graphql will want the same syntax for the client resolvers. |
Actually, it wasn't as hard as I thought: export interface EnumValuesMap {
[key: string]: any;
}
export interface TypeFieldsMap {
[fieldName: string]: GraphQLFieldResolver<any, any>;
}
export interface ResolversMap {
[typeName: string]: TypeFieldsMap | GraphQLScalarType | EnumValuesMap;
}
export async function buildResolversMap(options: BuildSchemaOptions): Promise<ResolversMap> {
const schema = await buildSchema(options);
const typeMap = schema.getTypeMap();
return Object.keys(typeMap)
.filter(typeName => !typeName.includes("__"))
.reduce<ResolversMap>((resolversMap, typeName) => {
const type = typeMap[typeName];
if ("getFields" in type) {
const fields = type.getFields();
resolversMap[typeName] = Object.keys(fields).reduce<TypeFieldsMap>(
(fieldsMap, fieldName) => {
const field = fields[fieldName];
if ("resolve" in field && field.resolve) {
fieldsMap[fieldName] = field.resolve;
}
return fieldsMap;
},
{},
);
}
if (type instanceof GraphQLScalarType) {
resolversMap[typeName] = type;
}
if (type instanceof GraphQLEnumType) {
resolversMap[typeName] = type.getValues().reduce<EnumValuesMap>((enumMap, enumValue) => {
enumMap[enumValue.name] = enumValue.value;
return enumMap;
}, {});
}
return resolversMap;
}, {});
} But for sure it's not a good idea to add a whole Feel free to experiment with this workaround, maybe I will take care about the proper integration someday 😉 |
I just wanted to add that I've been successful in using type-graphql in a client-side application with |
Creating separate builds will be possible in the future, while switching to monorepo with multiple plugin packages. So then I can publish And using it in browser in
Why do you still have to transpile ES6 classes? I thought that RN has a bit modern babel setup than ES5 😛 |
Unfortunately in order to support iOS React Native has to run on a somewhat older version of JavaScriptCore, so we still have to transpile ES6. |
Right, that's the point of the check. But does babel transpile also the |
A class is transpiled to a named function so the name is correctly set. In some case like |
@tonyxiao @shlomokraus
And let me know if it really works with |
Whoa this is super exciting. I'll give it a spin as soon as I can. |
@19majkel94 I gave it a quick spin, but personally I guess I'll wait until you've moved to the mono repo. The glob dependency (which in turn depends on fs) would force me to use something like browserify, which I don't want. Nevertheless, a great move, and I'm looking forward to using it clientside as soon as the dependencies are sorted out ;-) Appreciate the hard work you're putting in this library! |
@michelcve |
I just want to point out that Apollo Client 2.5 has client side state built in, it no longer requires apollo-link-state. |
I've just added an Apollo client state example: I've also tune a little bit some things to make it works correctly, so next release will be fully compatible with Apollo client state 🎉 So I can finally close this issue as done 🔒 In the future there will be |
hi @19majkel94, hate to comment on a closed issue but I couldn't find an issue or card somewhere that is tracking the progress on having a I'm very excited to use this in my projects but the package aliasing requires a bit more custom configuration that isn't possible for simple projects using create-react-app (not impossible of course, I can always eject or use craco but would prefer not to). |
Of course. Maybe I should write down my plans on monorepo and multiple packages + plugin system. |
I'm having an issue with the
|
@19majkel94 thanks for reply. Maybe it's related. Create React App seams to use |
|
it would be a lot easier of |
Is it possible to use GraphQL Code Generator to generate the typings for the client side resolvers at https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-client? |
@laukaichung you would need to emit schema file base on the client side schema as a script/build step separately, then you can point/merge server and client schema together with queries to generate the typings. |
Does type-graphql support client side resolvers for use with apollo-link-state? (https://blog.apollographql.com/the-future-of-state-management-dd410864cae2, https://hackernoon.com/storing-local-state-in-react-with-apollo-link-state-738f6ca45569)
The text was updated successfully, but these errors were encountered: