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
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!
https://strapi.io/blog/using-database-transactions-to-write-queries-in-strapi?utm_source=dev.to&utm_medium=post&utm_id=blog
I read the documentation for v3, but it doesn't tell me what mongoose methods I have access to from the beginning, so I was wondering if there were any guide or documentation that told me how to access all the Mongoose methods for article for example?
I tried calling
strapi.services.article.findMany({
offset: 10,
limit: 10,
where: {
id: ctx.query.id
}
})
But I got: strapi.services.article.findMany is not a function
It works if I do:
strapi.services.article.find(ctx.query)
Strapi provides a query API to interact with the database layer. Whether you're using mysql, postgres or mongodb, the API will have the same interface by definition (see query API documentation).
find is the way to go to find many entries.
PS: Since the article you posted is about database transaction with Strapi, I advise you to read my article about the caveats to be aware of.
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.
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.
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