-
builder.queryField('session', (t) =>
t.field({
type: SessionObject,
authScopes: { authenticated: true },
extensions: {
foo: 1,
},
})
); This doesn't seem to work with apollo server. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 17 replies
-
I think this is also preventing this from working for these scalars: https://github.com/Urigo/graphql-scalars/blob/master/src/scalars/json/JSONObject.ts#L17 |
Beta Was this translation helpful? Give feedback.
-
What is the behavior you are expecting from adding extensions? Not clear what you are trying to do, and what is not working. A more complete example with the expected behavior would be helpful |
Beta Was this translation helpful? Give feedback.
-
I think you are conflating 2 separate concepts:
Generally speaking, giraphql is focused on building graphql schemas, and resolving fields and data as part of that schema. From this perspective the "extensions" property added by graphql exists entirely outside the execution of a query (it is attached once the query has already been resolved). The way to extend the extensions property in an apollo response, you probably want to use a custom apollo plugin. Plugins for apollo are actually pretty easy and straight forward to write. You can see how the extensions are added by the tracing plugin here: https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/plugin/inlineTrace/index.ts#L85-L98 If you are trying define data for specific fields and then return that data for fields queried in the extensions property of a response you have a couple of options: apollo plugin + extensions
apollo plugin + giraphql pluginYou can write a very simple giraphql plugin that defines custom options so your custom data is typed correctly, the plugin would then just stick that data in the extensions object. The apollo plugin would work as described above. You could also handle the data aggregation during a query in the giraphql plugin, but would be more complex without much benefit. There are some other options as well, but I think the first option described above is probably the easiest and cleanest way to implement something like this |
Beta Was this translation helpful? Give feedback.
I think you are conflating 2 separate concepts:
graphql
library has a concept ofextensions
that are basically just objects that exists on most objects that make up a graphql schema (types, fields, etc). This is used in a lot of different ways, but mostly commonly this is the mechanism decorators attach data to a schema in a way that can be accessed at runtime. These extensions are frequently accessed through the info object when a resolver is wrapped by a plugin or decorator.extensions
properties added in your schema. This property is attached by apollo plugins, and is a non-standard…