Trying to setup subscriptions through apollo, both on the backend and frontend. The error arises when trying to call subscribeToMore function of the Query component. Although it clearly says that the schema is not a GraphQL schema, was not able to find any issues.
I have a suspicion, since I am using merge-graphql-schemas to merge typeDefs and revolvers and passing the merged schema to SubscriptionServer it some how doesnt stitch it together with the Subscription Operation.
I have created a gist of all the related pieces.
TIA.
So I finally figured out the issue.
It indeed had to with merge-graphql-schemas library but due to my fault.
After going through docs, that said
Beware that mergeResolvers is simply merging plain Javascript objects together. This means that you should be careful with Queries, Mutations or Subscriptions with naming conflicts.
Which also showed on console logging.
So it comes out that there are different options depending on the server implementation.
So making the schema using const schema = makeExecutableSchema({ typeDefs, resolvers });
helped resolve my problem.
Intially I tried using const schema = buildSchema(typeDefs); but for some reason it didnt stitch the resolvers and they stopped from firing.
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 have existing database in dynamodb for our application. For one of our new React app, we want to use AWS Amplify and we are trying to use the existing tables.
I created a skeleton project and went to backend AWS AppSync console -> Data Sources and map the existing table to it. And I added that table definition to my schema.graphql in my react app. When I do an amplify push, I see it creating a new table in dynamodb, rather than pointing to the existing db.
I also tried to map one of the tables in AppSync Console, and did amplify pull from local project, assuming that will add the definition of the table in my local schema.graphql but that did not happen either. It did not pull down the details of the newly mapped data source from backend app sync console.
My existing db has lot of data and is shared with other applications as well. I do not want to create a new table.
Can you pls suggest how to accomplish this?
Also we have existing lamdba functions which we would want to leverage into this new Amplify project as well. Could you pls suggest pointers for this as well.
Any help is much appreciated!
Line 22 in the file below shows how the table name is constructed when the graphql.schema transformer runs; that is - the name is derived from the GraphQLAPI ID and this seems to be a one way process.
TableName: joinWithEnv('-', [SyncResourceIDs.syncTableName, Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')]),
https://github.com/aws-amplify/amplify-cli/blob/e1e07b245db0963c4655e646c53e7615febe2930/packages/graphql-transformer-core/src/util/syncUtils.ts
The only option then would be to try and patch the resulting CFN script.
You can use amplify import storage to import existing DynamoDB tables or S3 buckets.
more here: https://docs.amplify.aws/cli/storage/import/
Also look at
Re-use existing AppSync GraphQL API - it might help with reusing lambda functions, if they are wrapped by an API.
We are planning to migrate towards Apollo GraphQL, because of the Apollo federation feature which allows unifying multiple microservices behind a single GraphQL API. However we are using TypeGraphQL at the moment, and I believe them to be incompatible. The reason is that in Apollo federation I see you use special #key property
/* example from docs */
const typeDefs = gql`
type Query {
me: User
}
type User #key(fields: "id") {
id: ID!
username: String
}
`;
However, the schema for TypeGraphql is automatically generated from classes. Is there a way to still use both technologies, or they are mutually exclusive?
Typegraphql had added the support for it, check the examples here https://github.com/MichalLytek/type-graphql/tree/master/examples/apollo-federation
While it has support by using #Directive decorator, it's not quite easy to work with it on a large scale project. I'm currently implementing it on a complex project, and I'm not satisfied with the amount of boilerplate code needed to reference some type from another schema. There was some conversation about adding better support here:
https://github.com/MichalLytek/type-graphql/issues/351#issuecomment-549156066
I'm planning to add support if I will have time soon.
but it's still not implemented. I've created a repo where you can see minimal example (similar to one in type-graphql repo):
https://github.com/hrvojepavlinovic/apollo-federation-type-graphql
I've seen several sources describe the (root, args, context, info) arguments to a graphql-yoga resolver, but I am still searching for the real documentation of a graphql-yoga resolver. There are a few blog posts that mention the resolver arguments:
prisma blog - Feb 2017 - GraphQL Schemas, TypeDefs & Resolvers Explained
prisma blog - Feb 2018 - Demystifying the info Argument in GraphQL Resolvers
I know that prisma has built graphql-yoga on graphql.js via graphql-tools, and it appears that graphql.js documents these parameters at graphql.org - Root fields & resolvers, but it's not clear if graphql.org is the main place where graphql.js is documented, and even if it was, it is not clear to me that as a user of graphql-yoga I should defer to the documentation of graphql.js.
In addition, prisma has built graphql-yoga on apollo-server; is the documentation for apollo-server most applicable here?
It doesn't appear that these arguments are part of the GraphQL spec.
Where is the real documentation for the arguments to a graphql-yoga resolver? If that is not available and documented, where in the graphql-yoga source is the function that expects the arguments to take this shape?
TL;DR
For use with graphql-yoga, you probably want to follow apollo-server's docs for resolvers in the graphql-tools section for Resolver function signature.
Details
To know which docs to use, one needs to understand the full tech stack: prisma built stuff on top of tools by apollo, which in turn is built on top of the reference implementation of GraphQL, graphql.js. Each layer of this stack has a separate docs site.
You can follow the trail from the graphql-yoga README, which says it is built on apollo-server, whose own README in turn says:
Apollo Server works with any GraphQL schema built with GraphQL.js, so you can build your schema with that directly or with a convenience library such as graphql-tools.
So graphql-yoga is an opinionated, batteries-included form of apollo-server, which takes schemas from graphql.js but is likely to have more seamless integration with schemas specified with apollo's own graphql-tools.
I like GraphQL and another libraries around GraphQL. I like GraphQL tools. But I found that I need a relation map. I thought that such tool had to exist. But I have not found. Does it exist?
If you are asking for a visual representation of relations, you could use GraphQL introspection to achieve this. Take a look on GraphQL Voyager:
Demo:
https://apis.guru/graphql-voyager/
Copy the introspection query, paste and run it on your GraphQL API endpoint.Copy the results into GraphQL Voyager. You should get a nice visual representation of your data relations available through your GraphQL API.
Github:
https://github.com/APIs-guru/graphql-voyager