Resolve resolves a query using the given options. The caller must call Close on the result when done consuming it.
(ctx context.Context, opts *ResolveOptions)
| 124 | // Resolve resolves a query using the given options. |
| 125 | // The caller must call Close on the result when done consuming it. |
| 126 | func (r *Runtime) Resolve(ctx context.Context, opts *ResolveOptions) (res ResolverResult, info *ResolveInfo, resErr error) { |
| 127 | // Since claims don't really make sense for some resolver use cases, it's easy to forget to set them. |
| 128 | // Adding an early panic to catch this. |
| 129 | if opts.Claims == nil { |
| 130 | panic("received nil claims") |
| 131 | } |
| 132 | |
| 133 | ctx, span := tracer.Start(ctx, "runtime.Resolve", trace.WithAttributes(attribute.String("resolver", opts.Resolver))) |
| 134 | var cacheHit bool |
| 135 | defer func() { |
| 136 | observability.AddRequestAttributes(ctx, attribute.Bool("query.cache_hit", cacheHit)) |
| 137 | if resErr != nil { |
| 138 | span.SetAttributes(attribute.String("err", resErr.Error())) |
| 139 | } |
| 140 | span.End() |
| 141 | }() |
| 142 | |
| 143 | // Initialize the resolver |
| 144 | initializer, ok := ResolverInitializers[opts.Resolver] |
| 145 | if !ok { |
| 146 | return nil, nil, fmt.Errorf("no resolver found for name %q", opts.Resolver) |
| 147 | } |
| 148 | resolver, err := initializer(ctx, &ResolverOptions{ |
| 149 | Runtime: r, |
| 150 | InstanceID: opts.InstanceID, |
| 151 | Properties: opts.ResolverProperties, |
| 152 | Args: opts.Args, |
| 153 | Claims: opts.Claims, |
| 154 | ForExport: false, |
| 155 | }) |
| 156 | if err != nil { |
| 157 | return nil, nil, err |
| 158 | } |
| 159 | defer resolver.Close() |
| 160 | |
| 161 | err = resolver.Validate(ctx) |
| 162 | if err != nil { |
| 163 | var invalidErr *ResolverUnusedFieldsError |
| 164 | if !errors.As(err, &invalidErr) { |
| 165 | return nil, nil, err |
| 166 | } |
| 167 | |
| 168 | cfg, cfgErr := r.InstanceConfig(ctx, opts.InstanceID) |
| 169 | if cfgErr != nil { |
| 170 | return nil, nil, fmt.Errorf("failed to get instance config: %w", cfgErr) |
| 171 | } |
| 172 | |
| 173 | if cfg.StrictResolverProps { |
| 174 | return nil, nil, err |
| 175 | } |
| 176 | info = &ResolveInfo{ |
| 177 | Warnings: []string{invalidErr.Error()}, |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Get the cache key |
| 182 | cacheKey, ok, err := resolver.CacheKey(ctx) |
| 183 | if err != nil { |
no test coverage detected