Ariadne has been very useful for our team which uses GraphQL backed by Python services.
When we add new fields to a type, existing records in our underlying database (DynamoDB) do not have the new attribute - so we run into a ValidationError (missing) when creating a Python object with newly generated Pydantic model. The fix for this would be to add the default = None for attributes that are Optional, which allows creation of the model class instance to continue even if the new attribute is not in the old record.
Is there already a way to do this that we're not leveraging properly?
# In schema.graphql which is our config `schema_path`
type Location {
locationId: ID!
parentId: ID
name: String
}
# In queries.graphql which is our config `queries_path`
fragment Location on Location {
locationId
parentId
name
}
After running codegen we get:
# generated/fragments.py
class Location(BaseModel):
locationId: str
parentId: Optional[str]
name: Optional[str]
Ariadne has been very useful for our team which uses GraphQL backed by Python services.
When we add new fields to a type, existing records in our underlying database (DynamoDB) do not have the new attribute - so we run into a ValidationError (missing) when creating a Python object with newly generated Pydantic model. The fix for this would be to add the default
= None
for attributes that areOptional
, which allows creation of the model class instance to continue even if the new attribute is not in the old record.Is there already a way to do this that we're not leveraging properly?
After running codegen we get:
We'd like: