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

How can I attach a resolver to a field in Appsync with SAM? #3685

Open
peragethemte opened this issue Nov 18, 2024 · 2 comments
Open

How can I attach a resolver to a field in Appsync with SAM? #3685

peragethemte opened this issue Nov 18, 2024 · 2 comments
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@peragethemte
Copy link

I have a GraphQL schema with a query. The query uses a lambda resolver that connects to a REST API and fetches the data. I want to have the field TimeSchedules on the type AccessGroup to use a different resolver and I've managed to get this to work in the console but it doesn't seem to be possible with SAM.

Parts of schema:

type Query {
  getAccessGroup(site: ID!, id: ID!): AccessGroup
}

type AccessGroup {
  id: ID!
  customerReference: String!
  lockCount: Int!
  userCount: Int!
  TimeSchedules: TimeSchedulesResults
}

On the REST Api access groups have time schedules but they're two different calls, and as I don't always need the latter, I think it's better to have it like this.

In SAM, I've tried this:

  GraphQLVBVAAPI:
      Type: AWS::Serverless::GraphQLApi
      Properties:
        SchemaUri: ./graphql/schema.graphql
        Resolvers:                                                 
          Query:
            getAccessGroup:
              Runtime:
                Name: APPSYNC_JS
                Version: "1.0.0"
              Pipeline:
                - lambdaResolver  
            AccessGroup:
              Runtime:
                Name: APPSYNC_JS
                Version: "1.0.0"
              Pipeline:
                - lambdaResolver

But then I get an error saying

No field named AccessGroup found on type Query

This is quite easy in the Console where I can just attach a resolver to the spesific field itself.

Any suggestions?

@peragethemte peragethemte added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Nov 18, 2024
@roger-zhangg
Copy link
Member

Hi peragethemte, sorry for the delayed response. I understand your request, I see you have defined Query as follows :

type Query {
  getAccessGroup(site: ID!, id: ID!): AccessGroup
}

Which doesn't have a AccessGroup prop, could you help to elaborate more on how did you make it work on console? Thanks

@roger-zhangg roger-zhangg added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jan 24, 2025
@peragethemte
Copy link
Author

Hi @roger-zhangg ! The id is the Id of the access group. But as each access group might have a time schedule, it would be nice to request the time schedule along with the access group whenever I like that.

In the console it is easy to attach a resolver to a field

Image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

2 participants