Skip to content

Injecting subgraph configuration - How to modify Query Field after it has been created? #992

Answered by 2snEM6
2snEM6 asked this question in Q&A
Discussion options

You must be logged in to vote

I got it working by overriding queryField and doing something like this:

queryField(
    name: string,
    field: QueryFieldThunk<PothosSchemaTypes.ExtendDefaultTypes<Types>>,
  ): void {
    const builtField = field(new QueryFieldBuilder(this));
    this.configStore.addFields('Query', () => ({
      [name]: builtField,
    }));

    if (this.currentSubgraph) {
      this.fieldRefSubgraphWeakMap.set(builtField, this.currentSubgraph);
    }

    this.configStore.onFieldUse(builtField, (fieldConfig) => {
      const subgraph = this.fieldRefSubgraphWeakMap.get(builtField);
      if (subgraph) {
        // eslint-disable-next-line no-param-reassign
        fieldConfig.pothosOptions.subGraphs = [

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@2snEM6
Comment options

Answer selected by 2snEM6
@2snEM6
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants