Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to Resolver Info in Modus Functions #730

Open
danstarns opened this issue Jan 25, 2025 · 1 comment
Open

Access to Resolver Info in Modus Functions #730

danstarns opened this issue Jan 25, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@danstarns
Copy link

danstarns commented Jan 25, 2025

Hi team,

I wanted to request the ability to access resolver info within Modus functions, similar to how GraphQL resolvers get an info parameter. Can someone confirm if this is something we could add to Modus?

Use Cases

  • Query Optimization: Build database queries based on requested fields
  • Authentication: Field-level authorization and access control
  • Root-Level Query Building: Optimize joins and prevent N+1 queries
  • Plugin Development: Enable Text-to-GraphQL and schema-aware tooling
  • Operation Analysis: Access operation type and name for metrics/logging

Implementation Examples

Query Optimization

export function getMovies(info: ResolverInfo): Movie[] {
  const requestedFields = info.fieldNodes[0].selectionSet.selections;
  
  const query = `
    MATCH (m:Movie)
    RETURN m.${requestedFields.map(f => f.name.value).join(', m.')}
  `;
  
  return executeQuery(query);
}

Authentication Patterns

export function getMovies(info: ResolverInfo): Movie[] {
  const operation = info.operation.name;
  const sensitiveFields = findSensitiveFields(info.fieldNodes[0]);
  requirePermissions(sensitiveFields);
  
  const query = buildSecureQuery(requestedFields);
  return executeQuery(query);
}

Text-to-GraphQL Plugins

export function textToQuery(question: string, info: ResolverInfo): QueryResult {
  const schema = info.schema;
  const generatedQuery = llmGenerateQuery(question, schema);
  
  const operationType = info.operation.operation;
  return executeQuery(generatedQuery, operationType);
}

Go Implementation

func FetchMovies(page int, search string, info *ResolverInfo) (string, error) {
    requestedFields := info.FieldNodes[0].SelectionSet.Selections
    
    query := fmt.Sprintf(`{
        movies(func: has(type.Movie), first: 10, offset: %d) {
            %s
        }
    }`, page * 10, buildFieldSelection(requestedFields))
    
    return executeDgraphQuery(query)
}

Tools using Resolve info

There are plenty of tools out there that use the resolve info, here is a list for inspiration:

  1. https://github.com/neo4j/graphql
  2. https://www.graphql-debugger.com
  3. https://www.npmjs.com/package/@opentelemetry/instrumentation-graphql
  4. https://github.com/maticzav/graphql-shield
  5. https://the-guild.dev/graphql/mesh/v1/auth
  6. https://hasura.io/
  7. https://www.npmjs.com/package/graphql-depth-limit
  8. https://github.com/pa-bru/graphql-cost-analysis
  9. ...
@mattjohnsonpint
Copy link
Member

Thanks for the request and the use cases! We will discuss internally and get back to you here.

@mattjohnsonpint mattjohnsonpint added the enhancement New feature or request label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants