question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I like what I’m seeing - I’m curious - I need to be able to add attributes for federation support

ie sample schema:

type Post @key(fields: "id") {
  id: ID!
  title: String!
  content: String!
  published: Boolean!
  createdAt: String!
  userId: Int
  user: User
}


extend type Query {
  posts: [Post!]!
  post(id: ID!): Post
}

extend type User @key(fields: "id") {
  id: ID! @external
  posts: [Post]
}

Is this possible ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
unlightcommented, Oct 12, 2021

@sgentile Example should work with next version

/// @NG.Directive('@extends')
/// @NG.Directive('@key(fields: "id")')
model User {
    /// @NG.Directive('@external')
    id String @id
}

generator nestgraphql {
    fields_NG_from = "@nestjs/graphql"
    fields_NG_output = false
    fields_NG_model = true
}
0reactions
sgentilecommented, Oct 13, 2021

Thank you!

Question… and I probably overlooked this: Apply ‘extends’ and @key is great’ there is another use case with this - you can see this in the post schema:

extend type User @key(fields: "id") {
  id: ID! @external
  posts: [Post]
}

This User type is not part of ‘Posts’ Prisma schema, however this is what links the above user model as shown here: https://github.com/sgentile/nest-apollo-federation/blob/main/posts-service/src/posts/schema.graphql

Just for reference this is then used in the resolver- ie.: @ResolveField(‘user’) getUser(@Parent() post: Post) { return { __typename: ‘User’, id: post.userId }; }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Federation - Wikipedia
A federation is a political entity characterized by a union of partially self-governing provinces, states, or other regions under a central federal ...
Read more >
Federation Definition & Meaning - Merriam-Webster
an encompassing political or societal entity formed by uniting smaller or more localized entities: such as ; a · a federal government ;...
Read more >
Federation | Definition, Examples, Government, & Difference ...
federation, the government of a federal community. In such a model there are two levels of government, one dealing with the common and...
Read more >
Federation Of American Scientists – Science for a safer, more ...
At the Federation of American Scientists, we are obsessed with outcomes, not just the myriad ways that science and technology can make the...
Read more >
federation - Wiktionary
Act of joining together into a single political entity. · Array of nations or states that are unified under one central authority which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found