Repository: strawberry-graphql/strawberry

Issue:
Undefined variable issue in 0.77.6
With the latest release of #1213, this [line](https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/types/nodes.py#L40) raises a KeyError when a variable is used in a query, but not defined in the payload under the key `variables`.

This used to work, and, I guess, is ok when the variable/argument is optional.

I do not know what the specs are, meaning if variable definition should be enforced all the way. If it's the way to go, maybe there should be a validation step/graceful way to handle such a case.

If not, `return info.variable_values.get(name)` should do the trick.


Discussion:
@jkimbo do you know what the spec says?

I think I've seen other frameworks fail in this case, but I might be wrong
Hmm I'm not sure. I would have assumed validation would have failed if you were not passing a variable that was defined in the query but I could be wrong. Will check. 
Can't find anything explicit about it in the spec but @g-as makes a good point that if variable/arguments are optional then you shouldn't have to pass them in the variable payload. So I'll make the change to `.get(name)`

Resolving patch:
diff --git a/strawberry/types/nodes.py b/strawberry/types/nodes.py
--- a/strawberry/types/nodes.py
+++ b/strawberry/types/nodes.py
@@ -37,7 +37,7 @@ def convert_value(info: GraphQLResolveInfo, node: GQLValueNode) -> Any:
     if isinstance(node, GQLVariableNode):
         # Look up variable
         name = node.name.value
-        return info.variable_values[name]
+        return info.variable_values.get(name)
     if isinstance(node, GQLListValueNode):
         return [convert_value(info, value) for value in node.values]
     if isinstance(node, GQLObjectValueNode):


Test patch:
diff --git a/tests/schema/test_info.py b/tests/schema/test_info.py
--- a/tests/schema/test_info.py
+++ b/tests/schema/test_info.py
@@ -226,6 +226,55 @@ def test_arg(
     ]
 
 
+def test_info_selected_fields_undefined_variable():
+    @strawberry.type
+    class Result:
+        ok: bool
+
+    selected_fields = None
+
+    @strawberry.type
+    class Query:
+        @strawberry.field
+        def hello(
+            self, info: Info[str, str], optional_input: Optional[str] = "hi"
+        ) -> Result:
+            nonlocal selected_fields
+            selected_fields = info.selected_fields
+            return Result(ok=True)
+
+    schema = strawberry.Schema(query=Query)
+    query = """
+    query MyQuery($optionalInput: String) {
+        hello(optionalInput: $optionalInput) {
+            ok
+        }
+    }
+    """
+    result = schema.execute_sync(query, variable_values={})
+
+    assert not result.errors
+    assert selected_fields == [
+        SelectedField(
+            name="hello",
+            directives={},
+            alias=None,
+            arguments={
+                "optionalInput": None,
+            },
+            selections=[
+                SelectedField(
+                    name="ok",
+                    alias=None,
+                    arguments={},
+                    directives={},
+                    selections=[],
+                )
+            ],
+        )
+    ]
+
+
 @pytest.mark.parametrize(
     "return_type,return_value",
     [