| 48 | } |
| 49 | |
| 50 | func (i *GraphQLCrafter) Craft(ctx context.Context, filepath string) (*api.Attestation_Material, error) { |
| 51 | i.logger.Debug().Str("path", filepath).Msg("decoding GraphQL SDL file") |
| 52 | |
| 53 | content, err := os.ReadFile(filepath) |
| 54 | if err != nil { |
| 55 | return nil, fmt.Errorf("can't open the file: %w", err) |
| 56 | } |
| 57 | |
| 58 | source := &ast.Source{Name: filepath, Input: string(content)} |
| 59 | doc, parseErr := parser.ParseSchema(source) |
| 60 | if parseErr != nil { |
| 61 | i.logger.Debug().Err(parseErr).Msg("error decoding file") |
| 62 | return nil, fmt.Errorf("invalid GraphQL SDL file: %w", ErrInvalidMaterialType) |
| 63 | } |
| 64 | |
| 65 | m, err := uploadAndCraft(ctx, i.input, i.backend, filepath, i.logger) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | |
| 70 | i.injectAnnotations(m, doc) |
| 71 | |
| 72 | return m, nil |
| 73 | } |
| 74 | |
| 75 | func (i *GraphQLCrafter) injectAnnotations(m *api.Attestation_Material, doc *ast.SchemaDocument) { |
| 76 | if m.Annotations == nil { |